Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -48,14 +48,6 @@ def respond(
|
|
48 |
|
49 |
return responses
|
50 |
|
51 |
-
# Function to generate response boxes dynamically
|
52 |
-
def generate_response_boxes(models):
|
53 |
-
response_boxes = []
|
54 |
-
for model_name in models:
|
55 |
-
response_box = gr.Textbox(label=f"Response from {model_name}", interactive=False)
|
56 |
-
response_boxes.append(response_box)
|
57 |
-
return response_boxes
|
58 |
-
|
59 |
# Build Gradio app
|
60 |
def create_demo():
|
61 |
with gr.Blocks() as demo:
|
@@ -82,45 +74,34 @@ def create_demo():
|
|
82 |
minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"
|
83 |
)
|
84 |
|
85 |
-
# Model Selection Section
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
)
|
92 |
|
93 |
# Dynamic Response Section
|
94 |
-
|
|
|
95 |
|
|
|
96 |
def generate_responses(
|
97 |
-
message,
|
98 |
):
|
99 |
if len(selected_models) != 2:
|
100 |
-
return "Error: Please select exactly two models to compare."
|
101 |
responses = respond(
|
102 |
-
message,
|
103 |
)
|
104 |
-
|
105 |
-
for model_name in selected_models:
|
106 |
-
outputs.append(responses.get(model_name, ""))
|
107 |
-
return outputs
|
108 |
|
109 |
# Add a button for generating responses
|
110 |
submit_button = gr.Button("Generate Responses")
|
111 |
-
|
112 |
-
# Link button click to generate responses
|
113 |
submit_button.click(
|
114 |
generate_responses,
|
115 |
-
inputs=[user_message,
|
116 |
-
outputs=
|
117 |
-
)
|
118 |
-
|
119 |
-
# Update response boxes when models are selected
|
120 |
-
selected_models.change(
|
121 |
-
lambda selected: generate_response_boxes(selected),
|
122 |
-
inputs=[selected_models],
|
123 |
-
outputs=response_boxes, # Update response boxes dynamically
|
124 |
)
|
125 |
|
126 |
return demo
|
|
|
48 |
|
49 |
return responses
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
# Build Gradio app
|
52 |
def create_demo():
|
53 |
with gr.Blocks() as demo:
|
|
|
74 |
minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"
|
75 |
)
|
76 |
|
77 |
+
# Model Selection Section
|
78 |
+
selected_models = gr.CheckboxGroup(
|
79 |
+
choices=list(model_options.keys()),
|
80 |
+
label="Select exactly two models to compare",
|
81 |
+
value=["Llama-3.1-70B", "Qwen-2.5-1.5B-Instruct"], # Default models
|
82 |
+
)
|
|
|
83 |
|
84 |
# Dynamic Response Section
|
85 |
+
response_box1 = gr.Textbox(label="Response from Model 1", interactive=False)
|
86 |
+
response_box2 = gr.Textbox(label="Response from Model 2", interactive=False)
|
87 |
|
88 |
+
# Function to generate responses
|
89 |
def generate_responses(
|
90 |
+
message, system_message, max_tokens, temperature, top_p, selected_models
|
91 |
):
|
92 |
if len(selected_models) != 2:
|
93 |
+
return "Error: Please select exactly two models to compare.", ""
|
94 |
responses = respond(
|
95 |
+
message, [], system_message, max_tokens, temperature, top_p, selected_models
|
96 |
)
|
97 |
+
return responses.get(selected_models[0], ""), responses.get(selected_models[1], "")
|
|
|
|
|
|
|
98 |
|
99 |
# Add a button for generating responses
|
100 |
submit_button = gr.Button("Generate Responses")
|
|
|
|
|
101 |
submit_button.click(
|
102 |
generate_responses,
|
103 |
+
inputs=[user_message, system_message, max_tokens, temperature, top_p, selected_models],
|
104 |
+
outputs=[response_box1, response_box2], # Link to response boxes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
)
|
106 |
|
107 |
return demo
|