nikunjcepatel commited on
Commit
d7f2c99
·
verified ·
1 Parent(s): 2a864c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -15
app.py CHANGED
@@ -24,7 +24,7 @@ MODEL_OPTIONS = [
24
  # History storage
25
  history = []
26
 
27
- def generate_comparisons_with_history(input_text, selected_models):
28
  global history
29
  results = {}
30
  for model in selected_models:
@@ -64,20 +64,34 @@ def generate_comparisons_with_history(input_text, selected_models):
64
  }
65
  history.append(history_entry)
66
 
67
- return results, history
 
 
 
 
 
 
 
 
68
 
69
  # Create Gradio interface with multiple model selection and history
70
- iface = gr.Interface(
71
- fn=generate_comparisons_with_history,
72
- inputs=[
73
- gr.Textbox(lines=2, label="Input Text", placeholder="Enter your query here"),
74
- gr.CheckboxGroup(choices=MODEL_OPTIONS, label="Select Models", value=[MODEL_OPTIONS[0]])
75
- ],
76
- outputs=[
77
- gr.JSON(label="Model Comparisons"),
78
- gr.JSON(label="History")
79
- ],
80
- title="Compare Outputs and Maintain History"
81
- )
 
 
 
 
 
 
 
82
 
83
- iface.launch()
 
24
  # History storage
25
  history = []
26
 
27
+ def generate_comparisons_with_history(input_text, selected_models, history_state):
28
  global history
29
  results = {}
30
  for model in selected_models:
 
64
  }
65
  history.append(history_entry)
66
 
67
+ # Update the history state
68
+ history_state = history
69
+
70
+ return results, history_state
71
+
72
+ def clear_history():
73
+ global history
74
+ history = []
75
+ return history
76
 
77
  # Create Gradio interface with multiple model selection and history
78
+ with gr.Blocks() as demo:
79
+ input_text = gr.Textbox(lines=2, label="Input Text", placeholder="Enter your query here")
80
+ selected_models = gr.CheckboxGroup(choices=MODEL_OPTIONS, label="Select Models", value=[MODEL_OPTIONS[0]])
81
+
82
+ # Define output components with scrollable containers
83
+ output_comparisons = gr.JSON(label="Model Comparisons", elem_id="output-comparisons")
84
+ output_history = gr.JSON(label="History", elem_id="output-history")
85
+
86
+ clear_history_button = gr.Button("Clear History")
87
+
88
+ # Add scrollbar to the output JSON areas with CSS
89
+ output_comparisons.style(height="300px", overflow="auto")
90
+ output_history.style(height="300px", overflow="auto")
91
+
92
+ clear_history_button.click(clear_history, outputs=output_history)
93
+
94
+ demo.submit(generate_comparisons_with_history, inputs=[input_text, selected_models, gr.State()], outputs=[output_comparisons, output_history])
95
+
96
+ demo.launch()
97