rathore11 commited on
Commit
f83e3cf
·
verified ·
1 Parent(s): 81917a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -7
app.py CHANGED
@@ -3,6 +3,7 @@ import gradio as gr
3
  import requests
4
  import inspect
5
  import pandas as pd
 
6
 
7
  # (Keep Constants as is)
8
  # --- Constants ---
@@ -11,13 +12,38 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
11
  # --- Basic Agent Definition ---
12
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
13
  class BasicAgent:
14
- def __init__(self):
15
- print("BasicAgent initialized.")
16
- def __call__(self, question: str) -> str:
17
- print(f"Agent received question (first 50 chars): {question[:50]}...")
18
- fixed_answer = "This is a default answer."
19
- print(f"Agent returning fixed answer: {fixed_answer}")
20
- return fixed_answer
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  def run_and_submit_all( profile: gr.OAuthProfile | None):
23
  """
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from transformers import pipeline
7
 
8
  # (Keep Constants as is)
9
  # --- Constants ---
 
12
  # --- Basic Agent Definition ---
13
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
14
  class BasicAgent:
15
+ def __init__(self):
16
+ print("Let me get ready ...")
17
+ self.pipeline = pipeline(
18
+ "text2text-generation",
19
+ model="google/flan-t5-base",
20
+ tokenizer="google/flan-t5-base",
21
+ max_length=256,
22
+ do_sample=False
23
+ )
24
+
25
+ self.system_prompt = (
26
+ "You are a general AI assistant. I will ask you a question. "
27
+ "Report your thoughts, and finish your answer with the following template: "
28
+ "FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible "
29
+ "OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma "
30
+ "to write your number neither use units such as $ or percent sign unless specified otherwise. If you are "
31
+ "asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in "
32
+ "plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules "
33
+ "depending of whether the element to be put in the list is a number or a string."
34
+ )
35
+ def __call__(self, question: str) -> str:
36
+ prompt = f"{self.system_prompt}\n\nQuestion: {question}"
37
+ print(f"Prompt:\n{prompt[:300]}...") # Trimmed for logging
38
+
39
+ try:
40
+ result = self.pipeline(prompt)
41
+ answer = result[0]["generated_text"].strip()
42
+ print(f"Answer: {answer}")
43
+ return answer
44
+ except Exception as e:
45
+ print(f"Pipeline error: {e}")
46
+ return "FINAL ANSWER: ERROR"
47
 
48
  def run_and_submit_all( profile: gr.OAuthProfile | None):
49
  """