cetusian commited on
Commit
5c30376
·
verified ·
1 Parent(s): 36055ed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -35
app.py CHANGED
@@ -48,6 +48,13 @@ def respond(
48
 
49
  return responses
50
 
 
 
 
 
 
 
 
51
 
52
  # Build Gradio app
53
  def create_demo():
@@ -86,24 +93,6 @@ def create_demo():
86
  # Dynamic Response Section
87
  response_boxes = []
88
 
89
- def generate_response_boxes(models):
90
- # Clear current components
91
- response_boxes.clear()
92
- # Add new response boxes dynamically for only two models
93
- columns = []
94
- for model_name in models:
95
- with gr.Column() as response_column:
96
- response_box = gr.Textbox(label=f"Response from {model_name}", interactive=False)
97
- vote_button = gr.Button(f"Vote for {model_name}")
98
- vote_count = gr.Number(value=0, label=f"Votes for {model_name}")
99
- columns.append((model_name, response_column, response_box, vote_button, vote_count))
100
- return columns
101
-
102
- # Add a button for generating responses
103
- submit_button = gr.Button("Generate Responses")
104
- vote_state = gr.State([0] * len(model_options)) # Initialize votes for all models
105
-
106
- # Generate responses
107
  def generate_responses(
108
  message, history, system_message, max_tokens, temperature, top_p, selected_models
109
  ):
@@ -113,31 +102,20 @@ def create_demo():
113
  message, history, system_message, max_tokens, temperature, top_p, selected_models
114
  )
115
  outputs = []
116
- for model_name, _, response_box, *_ in response_boxes:
117
  outputs.append(responses.get(model_name, ""))
118
  return outputs
119
 
120
- # Handle votes
121
- def handle_votes(votes, model_name):
122
- index = list(model_options.keys()).index(model_name)
123
- votes[index] += 1
124
- return votes
125
 
126
  # Link button click to generate responses
127
  submit_button.click(
128
  generate_responses,
129
  inputs=[user_message, gr.State([]), system_message, max_tokens, temperature, top_p, selected_models],
130
- outputs=[response_box[2] for response_box in response_boxes], # Only output the response boxes
131
  )
132
 
133
- # Link voting buttons to handle votes
134
- for model_name, _, _, vote_button, vote_count in response_boxes:
135
- vote_button.click(
136
- lambda votes, name=model_name: handle_votes(votes, name),
137
- inputs=[vote_state],
138
- outputs=[vote_state, vote_count],
139
- )
140
-
141
  # Update response boxes when models are selected
142
  selected_models.change(
143
  lambda selected: generate_response_boxes(selected),
@@ -147,7 +125,6 @@ def create_demo():
147
 
148
  return demo
149
 
150
-
151
  if __name__ == "__main__":
152
  demo = create_demo()
153
- demo.launch()
 
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():
 
93
  # Dynamic Response Section
94
  response_boxes = []
95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  def generate_responses(
97
  message, history, system_message, max_tokens, temperature, top_p, selected_models
98
  ):
 
102
  message, history, system_message, max_tokens, temperature, top_p, selected_models
103
  )
104
  outputs = []
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, gr.State([]), system_message, max_tokens, temperature, top_p, selected_models],
116
+ outputs=response_boxes, # Only output the response boxes
117
  )
118
 
 
 
 
 
 
 
 
 
119
  # Update response boxes when models are selected
120
  selected_models.change(
121
  lambda selected: generate_response_boxes(selected),
 
125
 
126
  return demo
127
 
 
128
  if __name__ == "__main__":
129
  demo = create_demo()
130
+ demo.launch()