kpbotla commited on
Commit
afffde1
·
verified ·
1 Parent(s): 0ef9ceb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -1
app.py CHANGED
@@ -37,9 +37,10 @@ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
37
 
38
 
39
 
 
40
  class SmartAgentV2:
41
  def __init__(self):
42
- self.qa_model = pipeline("text2text-generation", model="google/flan-t5-base")
43
  self.summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
44
  self.whisper_model = whisper.load_model("base")
45
 
@@ -74,6 +75,15 @@ class SmartAgentV2:
74
  result = self.whisper_model.transcribe(filepath)
75
  return result["text"]
76
 
 
 
 
 
 
 
 
 
 
77
  def sum_food_sales(self, filepath):
78
  df = pd.read_excel(filepath)
79
  food_df = df[df["Category"].str.lower() == "food"]
@@ -94,6 +104,10 @@ class SmartAgentV2:
94
  if filepath := getattr(file, "name", None):
95
  if filepath.endswith(".mp3"):
96
  transcript = self.transcribe_audio(filepath)
 
 
 
 
97
  return transcript
98
  elif filepath.endswith(".xlsx") or filepath.endswith(".xls"):
99
  return self.sum_food_sales(filepath)
@@ -113,6 +127,7 @@ class SmartAgentV2:
113
  return "An error occurred processing the question."
114
 
115
 
 
116
  def run_and_submit_all( profile: gr.OAuthProfile | None):
117
  """
118
  Fetches all questions, runs the BasicAgent on them, submits all answers,
 
37
 
38
 
39
 
40
+
41
  class SmartAgentV2:
42
  def __init__(self):
43
+ self.qa_model = pipeline("text2text-generation", model="google/flan-t5-xl")
44
  self.summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
45
  self.whisper_model = whisper.load_model("base")
46
 
 
75
  result = self.whisper_model.transcribe(filepath)
76
  return result["text"]
77
 
78
+ def extract_ingredients(self, transcript):
79
+ ingredients = re.findall(r"(?:\ba|\ban|\bthe)?\s*([a-zA-Z\s]+?)\s*(?:\bof\b|\bcups?\b|\btablespoons?\b|\bteaspoons?\b|\bpinch\b)?", transcript)
80
+ ingredients = [i.strip().lower() for i in ingredients if len(i.strip()) > 2]
81
+ return ", ".join(sorted(set(ingredients)))
82
+
83
+ def extract_page_numbers(self, transcript):
84
+ numbers = re.findall(r"\b\d+\b", transcript)
85
+ return ", ".join(sorted(set(numbers), key=int))
86
+
87
  def sum_food_sales(self, filepath):
88
  df = pd.read_excel(filepath)
89
  food_df = df[df["Category"].str.lower() == "food"]
 
104
  if filepath := getattr(file, "name", None):
105
  if filepath.endswith(".mp3"):
106
  transcript = self.transcribe_audio(filepath)
107
+ if "ingredient" in q:
108
+ return self.extract_ingredients(transcript)
109
+ if "page" in q:
110
+ return self.extract_page_numbers(transcript)
111
  return transcript
112
  elif filepath.endswith(".xlsx") or filepath.endswith(".xls"):
113
  return self.sum_food_sales(filepath)
 
127
  return "An error occurred processing the question."
128
 
129
 
130
+
131
  def run_and_submit_all( profile: gr.OAuthProfile | None):
132
  """
133
  Fetches all questions, runs the BasicAgent on them, submits all answers,