rishabhsetiya commited on
Commit
d98c763
·
verified ·
1 Parent(s): 94e7541

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -6
app.py CHANGED
@@ -22,16 +22,37 @@ def generate_answer_rag(prompt, max_tokens=200):
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_tuning.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 fine_tuned_answer, rag_answer
35
 
36
 
37
  # -----------------------------
 
22
  # -----------------------------
23
  # Combined Answer Function
24
  # -----------------------------
25
+ import time
26
+ from concurrent.futures import ThreadPoolExecutor, as_completed
27
+
28
  def combined_generate(prompt, max_tokens):
29
  with ThreadPoolExecutor() as executor:
30
+ start_times = {"Fine-tuned": time.time(), "RAG": time.time()}
31
+
32
+ futures = {
33
+ executor.submit(generate_answer, model, tokenizer, device, prompt, max_tokens): "Fine-tuned",
34
+ executor.submit(generate_answer_rag, prompt, max_tokens): "RAG",
35
+ }
36
+
37
+ answers = {"Fine-tuned": "", "RAG": ""}
38
+ times = {"Fine-tuned": None, "RAG": None}
39
+
40
+ for future in as_completed(futures):
41
+ model_name = futures[future]
42
+ answers[model_name] = future.result()
43
+ times[model_name] = round(time.time() - start_times[model_name], 2)
44
+
45
+ # Format answers with time taken
46
+ ft_display = answers["Fine-tuned"]
47
+ if times["Fine-tuned"] is not None:
48
+ ft_display += f"\n\n⏱ Took {times['Fine-tuned']}s"
49
+
50
+ rag_display = answers["RAG"]
51
+ if times["RAG"] is not None:
52
+ rag_display += f"\n\n⏱ Took {times['RAG']}s"
53
 
54
+ yield ft_display, rag_display
 
55
 
 
56
 
57
 
58
  # -----------------------------