MythSus commited on
Commit
e16c63b
·
verified ·
1 Parent(s): 78249b8
Files changed (1) hide show
  1. app.py +74 -0
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import time
2
+ import gradio as gr
3
+
4
+ # -------------------------------
5
+ # Simulated QA Models
6
+ # -------------------------------
7
+ def qa_system(method, question):
8
+ start_time = time.time()
9
+
10
+ if not question.strip():
11
+ return "**Error:** Please enter a question.", 0.0, "0 seconds", ""
12
+
13
+ # Simulated response based on method
14
+ if method == "Retrieval-Augmented Generation (RAG)":
15
+ answer = "Using RAG: Based on retrieved financial documents, the answer is $95,000,000."
16
+ model_name = "RAG-based Model"
17
+ confidence = 0.92
18
+ else:
19
+ # Fine-tuned TinyLLaMA + LoRA response simulation
20
+ answer = "The total revenue in 2023 was $100,000,000."
21
+ model_name = "Fine-Tuned TinyLLaMA-1.1B (LoRA)"
22
+ confidence = 0.95
23
+
24
+ end_time = time.time()
25
+ response_time = round(end_time - start_time, 2)
26
+
27
+ return (
28
+ f"**Method:** {model_name}",
29
+ confidence,
30
+ f"{response_time} seconds",
31
+ answer
32
+ )
33
+
34
+ # -------------------------------
35
+ # Gradio UI
36
+ # -------------------------------
37
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
38
+ gr.Markdown(
39
+ """
40
+ # 📊 Comparative Financial QA System
41
+ Compare **Retrieval-Augmented Generation (RAG)**
42
+ and **Fine-Tuned TinyLLaMA LoRA** models for Microsoft's financial Q&A.
43
+ """
44
+ )
45
+
46
+ with gr.Row():
47
+ method = gr.Radio(
48
+ choices=["Retrieval-Augmented Generation (RAG)", "Fine-Tuned Model"],
49
+ label="Choose QA Method:",
50
+ value="Fine-Tuned Model"
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
+ submit_btn = gr.Button("Get Answer")
59
+
60
+ # Output section
61
+ method_output = gr.Markdown()
62
+ confidence_output = gr.Number(label="Model Confidence")
63
+ response_time_output = gr.Textbox(label="Response Time")
64
+ answer_output = gr.Markdown(label="Answer")
65
+
66
+ submit_btn.click(
67
+ qa_system,
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
+ demo.launch()