Spaces:
Sleeping
Sleeping
File size: 4,342 Bytes
04ca1b2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
"""
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) |