Spaces:
Sleeping
Sleeping
import gradio as gr | |
import os | |
from ui.dataset_input import create_dataset_input, load_example_dataset | |
from ui.analysis_screen import process_analysis_request | |
def create_app(): | |
""" | |
Create a streamlined Gradio app for dataset input and Bag of Words analysis. | |
Returns: | |
gr.Blocks: The Gradio application | |
""" | |
with gr.Blocks(title="LLM Response Comparator") as app: | |
# Application state to share data between tabs | |
dataset_state = gr.State({}) | |
analysis_results_state = gr.State({}) | |
# Dataset Input Tab | |
with gr.Tab("Dataset Input"): | |
dataset_inputs, example_dropdown, load_example_btn, create_btn, prompt, response1, model1, response2, model2 = create_dataset_input() | |
# Load example dataset | |
load_example_btn.click( | |
fn=load_example_dataset, | |
inputs=[example_dropdown], | |
outputs=[dataset_inputs] # Ensure `load_example_dataset` returns compatible data | |
) | |
# Save dataset to state | |
create_btn.click( | |
fn=lambda p, r1, m1, r2, m2: { | |
"entries": [ | |
{"prompt": p, "response": r1, "model": m1}, | |
{"prompt": p, "response": r2, "model": m2} | |
] | |
}, | |
inputs=[prompt, response1, model1, response2, model2], # Ensure these are valid Gradio components | |
outputs=[dataset_state] # Ensure `dataset_state` is correctly defined | |
) | |
# Analysis Tab | |
with gr.Tab("Analysis"): | |
analysis_options = gr.CheckboxGroup( | |
choices=["Bag of Words"], | |
value=["Bag of Words"], | |
label="Select Analyses to Run" | |
) | |
run_analysis_btn = gr.Button("Run Analysis", variant="primary") | |
analysis_output = gr.JSON(label="Analysis Results", visible=False) | |
# Run analysis | |
run_analysis_btn.click( | |
fn=process_analysis_request, | |
inputs=[dataset_state, analysis_options], # Removed None | |
outputs=[analysis_results_state, analysis_output] | |
) | |
return app | |
if __name__ == "__main__": | |
# Create and launch the app | |
app = create_app() | |
app.launch() |