Update app.py
Browse files
app.py
CHANGED
|
@@ -34,41 +34,73 @@ def qa_system(method, question):
|
|
| 34 |
# -------------------------------
|
| 35 |
# Gradio UI
|
| 36 |
# -------------------------------
|
| 37 |
-
with gr.Blocks(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
gr.Markdown(
|
| 39 |
"""
|
| 40 |
# 📊 Comparative Financial QA System
|
| 41 |
-
|
| 42 |
-
and **Fine-Tuned TinyLLaMA LoRA** models for Microsoft's financial Q&A.
|
| 43 |
"""
|
| 44 |
)
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
| 52 |
|
|
|
|
| 53 |
question = gr.Textbox(
|
| 54 |
label="Ask a question about Microsoft's 2022-2023 financials:",
|
| 55 |
placeholder="e.g., What was the total revenue in 2023?"
|
| 56 |
)
|
| 57 |
|
| 58 |
-
|
|
|
|
| 59 |
|
| 60 |
-
# Output section
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
submit_btn.click(
|
| 67 |
-
|
| 68 |
inputs=[method, question],
|
| 69 |
-
outputs=[method_output, confidence_output, response_time_output, answer_output]
|
| 70 |
)
|
| 71 |
|
| 72 |
# -------------------------------
|
| 73 |
# Launch for Hugging Face Spaces
|
| 74 |
-
|
|
|
|
|
|
|
|
|
| 34 |
# -------------------------------
|
| 35 |
# Gradio UI
|
| 36 |
# -------------------------------
|
| 37 |
+
with gr.Blocks(css="""
|
| 38 |
+
.radio-vertical .wrap {
|
| 39 |
+
flex-direction: column !important;
|
| 40 |
+
}
|
| 41 |
+
.radio-vertical .wrap > label {
|
| 42 |
+
margin-bottom: 8px !important;
|
| 43 |
+
margin-right: 0 !important;
|
| 44 |
+
}
|
| 45 |
+
.small-btn {
|
| 46 |
+
max-width: fit-content !important;
|
| 47 |
+
width: auto !important;
|
| 48 |
+
}
|
| 49 |
+
.small-btn button {
|
| 50 |
+
width: auto !important;
|
| 51 |
+
min-width: unset !important;
|
| 52 |
+
padding: 8px 16px !important;
|
| 53 |
+
font-size: 16px !important;
|
| 54 |
+
white-space: nowrap !important;
|
| 55 |
+
max-width: fit-content !important;
|
| 56 |
+
}
|
| 57 |
+
""") as demo:
|
| 58 |
gr.Markdown(
|
| 59 |
"""
|
| 60 |
# 📊 Comparative Financial QA System
|
| 61 |
+
An implementation comparing **Retrieval-Augmented Generation (RAG)** and a **Fine-Tuned on LoRA and Replay-Based Learning** GPT 2 model for answering questions on financial reports.
|
|
|
|
| 62 |
"""
|
| 63 |
)
|
| 64 |
|
| 65 |
+
# Radio buttons displayed vertically
|
| 66 |
+
method = gr.Radio(
|
| 67 |
+
choices=["Retrieval-Augmented Generation (RAG)", "Fine-Tuned Model"],
|
| 68 |
+
label="Choose QA Method:",
|
| 69 |
+
value="Fine-Tuned Model",
|
| 70 |
+
interactive=True,
|
| 71 |
+
elem_classes="radio-vertical"
|
| 72 |
+
)
|
| 73 |
|
| 74 |
+
# Question input
|
| 75 |
question = gr.Textbox(
|
| 76 |
label="Ask a question about Microsoft's 2022-2023 financials:",
|
| 77 |
placeholder="e.g., What was the total revenue in 2023?"
|
| 78 |
)
|
| 79 |
|
| 80 |
+
# Get Answer button — auto-sized
|
| 81 |
+
submit_btn = gr.Button("Get Answer", elem_classes="small-btn")
|
| 82 |
|
| 83 |
+
# Output section - initially hidden
|
| 84 |
+
with gr.Group(visible=False) as output_section:
|
| 85 |
+
method_output = gr.Markdown()
|
| 86 |
+
confidence_output = gr.Number(label="Model Confidence")
|
| 87 |
+
response_time_output = gr.Textbox(label="Response Time")
|
| 88 |
+
answer_output = gr.Markdown(label="Answer")
|
| 89 |
|
| 90 |
+
# Button click handler
|
| 91 |
+
def handle_submit(method_val, question_val):
|
| 92 |
+
# Show output section and get results
|
| 93 |
+
results = qa_system(method_val, question_val)
|
| 94 |
+
return [gr.Group(visible=True)] + list(results)
|
| 95 |
+
|
| 96 |
submit_btn.click(
|
| 97 |
+
handle_submit,
|
| 98 |
inputs=[method, question],
|
| 99 |
+
outputs=[output_section, method_output, confidence_output, response_time_output, answer_output]
|
| 100 |
)
|
| 101 |
|
| 102 |
# -------------------------------
|
| 103 |
# Launch for Hugging Face Spaces
|
| 104 |
+
# -------------------------------
|
| 105 |
+
if __name__ == "__main__":
|
| 106 |
+
demo.launch()
|