Spaces:
Running
Running
update code snippet
Browse files
app.py
CHANGED
|
@@ -66,6 +66,74 @@ PROVIDERS = {
|
|
| 66 |
"Perplexity": demo_perplexity,
|
| 67 |
}
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
demo = get_app(
|
| 70 |
models=list(PROVIDERS.keys()),
|
| 71 |
default_model="OpenAI Coder",
|
|
|
|
| 66 |
"Perplexity": demo_perplexity,
|
| 67 |
}
|
| 68 |
|
| 69 |
+
# Create code snippets for each provider
|
| 70 |
+
def get_code_snippet(provider):
|
| 71 |
+
if "OpenAI" in provider:
|
| 72 |
+
return """import gradio as gr
|
| 73 |
+
import ai_gradio
|
| 74 |
+
|
| 75 |
+
gr.load(
|
| 76 |
+
name='openai:gpt-4-turbo',
|
| 77 |
+
src=ai_gradio.registry,
|
| 78 |
+
title='AI Chat',
|
| 79 |
+
description='Chat with an AI model'
|
| 80 |
+
).launch()"""
|
| 81 |
+
elif "Gemini" in provider:
|
| 82 |
+
return """import gradio as gr
|
| 83 |
+
import ai_gradio
|
| 84 |
+
|
| 85 |
+
gr.load(
|
| 86 |
+
name='gemini:gemini-1.5-flash',
|
| 87 |
+
src=ai_gradio.registry,
|
| 88 |
+
title='AI Chat',
|
| 89 |
+
description='Chat with an AI model'
|
| 90 |
+
).launch()"""
|
| 91 |
+
elif "Groq" in provider:
|
| 92 |
+
return """import gradio as gr
|
| 93 |
+
import ai_gradio
|
| 94 |
+
|
| 95 |
+
gr.load(
|
| 96 |
+
name='groq:llama-3.2-70b-chat',
|
| 97 |
+
src=ai_gradio.registry,
|
| 98 |
+
title='AI Chat',
|
| 99 |
+
description='Chat with an AI model'
|
| 100 |
+
).launch()"""
|
| 101 |
+
return ""
|
| 102 |
+
|
| 103 |
+
import gradio as gr
|
| 104 |
+
|
| 105 |
+
# Modified get_app to include code snippets
|
| 106 |
+
def get_app(models, default_model, src, dropdown_label):
|
| 107 |
+
with gr.Blocks() as demo:
|
| 108 |
+
# Add code snippet display
|
| 109 |
+
code_component = gr.Code(
|
| 110 |
+
label="Code Snippet",
|
| 111 |
+
language="python",
|
| 112 |
+
value=get_code_snippet(default_model)
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
# Add dropdown and get the demo interface
|
| 116 |
+
model = gr.Dropdown(
|
| 117 |
+
choices=models,
|
| 118 |
+
value=default_model,
|
| 119 |
+
label=dropdown_label
|
| 120 |
+
)
|
| 121 |
+
|
| 122 |
+
# Update code snippet when model changes
|
| 123 |
+
def update_code(provider):
|
| 124 |
+
return get_code_snippet(provider)
|
| 125 |
+
|
| 126 |
+
model.change(
|
| 127 |
+
fn=update_code,
|
| 128 |
+
inputs=[model],
|
| 129 |
+
outputs=[code_component]
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
# Get the demo interface for the selected model
|
| 133 |
+
demo_interface = src[default_model]()
|
| 134 |
+
|
| 135 |
+
return demo
|
| 136 |
+
|
| 137 |
demo = get_app(
|
| 138 |
models=list(PROVIDERS.keys()),
|
| 139 |
default_model="OpenAI Coder",
|