rishabhsetiya commited on
Commit
1a05580
·
verified ·
1 Parent(s): 60dcea8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -9
app.py CHANGED
@@ -1,22 +1,58 @@
1
  import gradio as gr
2
- from fine_tuning import load_and_train, generate_answer
 
 
3
 
4
- # Load and train model
 
 
5
  model, tokenizer, device = load_and_train()
6
 
7
- # Wrap for Gradio
8
- def gradio_generate(prompt, max_tokens):
9
- return generate_answer(model, tokenizer, device, prompt, max_tokens)
 
 
 
 
 
 
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  iface = gr.Interface(
12
- fn=gradio_generate,
13
  inputs=[
14
  gr.Textbox(label="Enter your question:", lines=5, placeholder="Type your question here..."),
15
  gr.Slider(minimum=50, maximum=500, step=10, value=200, label="Max tokens to generate")
16
  ],
17
- outputs=gr.Textbox(label="Generated Answer"),
18
- title="Chat with My Fine-Tuned Model 🤖",
19
- description="This app allows you to ask questions about MakeMyTrip's financial data."
 
 
 
20
  ).queue()
21
 
22
  iface.launch()
 
 
1
  import gradio as gr
2
+ from concurrent.futures import ThreadPoolExecutor
3
+ import fine_tuned
4
+ from fine_tuned import load_and_train
5
 
6
+ # -----------------------------
7
+ # Load fine-tuned model
8
+ # -----------------------------
9
  model, tokenizer, device = load_and_train()
10
 
11
+ # -----------------------------
12
+ # RAG Backend (Stub Example)
13
+ # -----------------------------
14
+ def generate_answer_rag(prompt, max_tokens=200):
15
+ """
16
+ Replace this stub with your actual RAG pipeline.
17
+ For now, just a dummy response.
18
+ """
19
+ return f"[RAG answer for]: {prompt[:50]}..."
20
 
21
+
22
+ # -----------------------------
23
+ # Combined Answer Function
24
+ # -----------------------------
25
+ def combined_generate(prompt, max_tokens):
26
+ with ThreadPoolExecutor() as executor:
27
+ # Submit both tasks in parallel
28
+ ft_future = executor.submit(fine_tuned.generate_answer, model, tokenizer, device, prompt, max_tokens)
29
+ rag_future = executor.submit(generate_answer_rag, prompt, max_tokens)
30
+
31
+ fine_tuned_answer = ft_future.result()
32
+ rag_answer = rag_future.result()
33
+
34
+ return {
35
+ "Fine-tuned Model Answer": fine_tuned_answer,
36
+ "RAG Answer": rag_answer
37
+ }
38
+
39
+
40
+ # -----------------------------
41
+ # Gradio Interface
42
+ # -----------------------------
43
  iface = gr.Interface(
44
+ fn=combined_generate,
45
  inputs=[
46
  gr.Textbox(label="Enter your question:", lines=5, placeholder="Type your question here..."),
47
  gr.Slider(minimum=50, maximum=500, step=10, value=200, label="Max tokens to generate")
48
  ],
49
+ outputs=[
50
+ gr.Textbox(label="Fine-tuned Model Answer"),
51
+ gr.Textbox(label="RAG Answer")
52
+ ],
53
+ title="Compare Fine-tuned Model vs RAG 🤖📚",
54
+ description="Ask a question and get answers from both the fine-tuned model and the RAG pipeline."
55
  ).queue()
56
 
57
  iface.launch()
58
+