Spaces:
Sleeping
Sleeping
""" | |
Objectivity Analysis Suite | |
Main Application with Gradio Interface | |
""" | |
import gradio as gr | |
from models import MODELS | |
from text_analysis import analyze_text | |
from scenario import TOPICS, on_load_scenario, assess_objectivity | |
# Build the Gradio Interface with Tabs | |
with gr.Blocks(title="Objectivity Analysis Suite") as app: | |
gr.Markdown("# Objectivity Analysis Suite") | |
gr.Markdown("Choose a functionality below:") | |
with gr.Tabs(): | |
# Tab 1: Text Objectivity Analysis | |
with gr.TabItem("Text Analysis"): | |
gr.Markdown("## Texts Objectivity Analyzer") | |
gr.Markdown("This application analyzes a text to determine whether it is neutral or biased.") | |
with gr.Row(): | |
with gr.Column(scale=3): | |
model_dropdown = gr.Dropdown( | |
choices=list(MODELS.keys()), | |
label="Select a model", | |
value=list(MODELS.keys())[0] | |
) | |
text_input = gr.Textbox( | |
placeholder="Enter the text to be analyzed...", | |
label="Text to analyze", | |
lines=10 | |
) | |
analyze_button = gr.Button("Analyze the text") | |
with gr.Column(scale=2): | |
confidence_output = gr.Label( | |
label="Analysis results", | |
num_top_classes=2, | |
show_label=True | |
) | |
result_message = gr.Textbox(label="Detailed results", interactive=False) | |
analyze_button.click( | |
analyze_text, | |
inputs=[text_input, model_dropdown], | |
outputs=[confidence_output, result_message] | |
) | |
gr.Markdown("## How to use this application") | |
gr.Markdown(""" | |
1. Select a model from the drop-down. | |
2. Enter or paste the text to be analyzed. | |
3. Click **'Analyze the text'** to see the results. | |
""") | |
# Tab 2: Scenario-based Objectivity Assessment | |
with gr.TabItem("Scenario Assessment"): | |
gr.Markdown("## Bias Detection: Assessing Objectivity in Scenarios") | |
gr.Markdown("""Test your objectivity by evaluating a scenario and comparing your assessment with the model's prediction.""") | |
topic_dropdown = gr.Dropdown(choices=TOPICS, label="Select a Topic") | |
load_offline_button = gr.Button("Load Offline Scenario") | |
context_box = gr.Textbox(label="Context", interactive=False) | |
question_box = gr.Textbox(label="Question", interactive=False) | |
ans0_box = gr.Textbox(label="Answer A", interactive=False) | |
ans1_box = gr.Textbox(label="Answer B", interactive=False) | |
ans2_box = gr.Textbox(label="Answer C", interactive=False) | |
user_choice_radio = gr.Radio(choices=[], label="Select Your Answer") | |
assessment_box = gr.Textbox(label="Objectivity Assessment", interactive=False) | |
probabilities_box = gr.JSON(label="Confidence Probabilities") | |
assess_button = gr.Button("Assess Objectivity") | |
load_offline_button.click( | |
fn=on_load_scenario, | |
inputs=[topic_dropdown], | |
outputs=[context_box, question_box, ans0_box, ans1_box, ans2_box, user_choice_radio] | |
) | |
assess_button.click( | |
fn=assess_objectivity, | |
inputs=[context_box, question_box, ans0_box, ans1_box, ans2_box, user_choice_radio], | |
outputs=[assessment_box, probabilities_box] | |
) | |
gr.Markdown("## How It Works:") | |
gr.Markdown(""" | |
1. Select a topic from the dropdown. | |
2. Review the context, question, and 3 candidate answers. | |
3. Select your answer. | |
4. Click "Assess Objectivity" to see the model's evaluation. | |
""") | |
gr.Markdown("## Additional Instructions") | |
gr.Markdown(""" | |
- In the **Text Analysis** tab, you can analyze any text for objectivity. | |
- In the **Scenario evaluation** tab, you can load a scenario to test your objectivity. | |
""") | |
# Launch the app | |
if __name__ == "__main__": | |
app.launch(show_api=False) |