Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,59 @@
|
|
1 |
import gradio as gr
|
2 |
import sambanova_gradio
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import sambanova_gradio
|
3 |
|
4 |
+
# Define a function to load the selected model
|
5 |
+
def load_model(model_choice):
|
6 |
+
model = gr.load(
|
7 |
+
name=model_choice,
|
8 |
+
src=sambanova_gradio.registry
|
9 |
+
)
|
10 |
+
return model
|
11 |
+
|
12 |
+
# Available model choices
|
13 |
+
model_choices = [
|
14 |
+
"Meta-Llama-3.2-1B-lnstruct",
|
15 |
+
"Meta-Llama-3.2-3B-Instruct",
|
16 |
+
"Meta-Llama-3.1-88-Instruct",
|
17 |
+
"Meta-Llama-3.1-405B-lnstruct",
|
18 |
+
"Meta-Llama-3.1-70B-lnstruct"
|
19 |
+
]
|
20 |
+
|
21 |
+
# Create Gradio interface
|
22 |
+
with gr.Blocks() as demo:
|
23 |
+
gr.Markdown("# Meta-Llama Model Selector")
|
24 |
+
|
25 |
+
# Dropdown for selecting the model
|
26 |
+
model_choice = gr.Dropdown(
|
27 |
+
choices=model_choices,
|
28 |
+
label="Choose a Meta-Llama Model",
|
29 |
+
value="Meta-Llama-3.2-3B-Instruct" # default value
|
30 |
+
)
|
31 |
+
|
32 |
+
# Textbox for user input and output
|
33 |
+
input_box = gr.Textbox(
|
34 |
+
label="Input",
|
35 |
+
placeholder="Ask a question...",
|
36 |
+
examples=["Explain quantum gravity to a 5-year old.",
|
37 |
+
"How many R are there in the word Strawberry?"]
|
38 |
+
)
|
39 |
+
|
40 |
+
# Output for the model's response
|
41 |
+
output_box = gr.Textbox(label="Output")
|
42 |
+
|
43 |
+
# Button to generate the output
|
44 |
+
generate_button = gr.Button("Generate Response")
|
45 |
+
|
46 |
+
# Action when button is clicked
|
47 |
+
def generate_response(model_choice, user_input):
|
48 |
+
model = load_model(model_choice)
|
49 |
+
output = model.predict(user_input)
|
50 |
+
return output
|
51 |
+
|
52 |
+
generate_button.click(
|
53 |
+
generate_response,
|
54 |
+
inputs=[model_choice, input_box],
|
55 |
+
outputs=output_box
|
56 |
+
)
|
57 |
+
|
58 |
+
# Launch the Gradio app
|
59 |
+
demo.launch(share=True)
|