Toumaima commited on
Commit
73f1372
·
verified ·
1 Parent(s): 4d91f18

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -0
app.py CHANGED
@@ -114,6 +114,23 @@ class BasicAgent:
114
 
115
  return None
116
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
 
118
 
119
  def __call__(self, question: str, video_path: str = None) -> str:
@@ -123,6 +140,9 @@ class BasicAgent:
123
  logic_answer = self.handle_logic_riddles(question)
124
  if logic_answer is not None:
125
  return f"🧠 Logic Answer: {logic_answer}"
 
 
 
126
 
127
  if video_path:
128
  transcription = self.call_whisper(video_path)
 
114
 
115
  return None
116
 
117
+
118
+ def solve_riddle(self, riddle: str) -> str:
119
+ """Fallback riddle solver using QA pipeline with general logic context."""
120
+ riddle_context = (
121
+ "You are a riddle-solving assistant. Try to give a short and logical answer to riddles.\n"
122
+ "Examples:\n"
123
+ "Q: What has keys but can't open locks?\nA: A piano\n"
124
+ "Q: What runs but never walks?\nA: Water\n"
125
+ "Q: What comes once in a minute, twice in a moment, but never in a thousand years?\nA: The letter M\n"
126
+ f"Q: {riddle}\nA:"
127
+ )
128
+ try:
129
+ result = self.qa_pipeline(question=riddle, context=riddle_context)
130
+ return result["answer"]
131
+ except Exception as e:
132
+ return f"Could not solve riddle: {e}"
133
+
134
 
135
 
136
  def __call__(self, question: str, video_path: str = None) -> str:
 
140
  logic_answer = self.handle_logic_riddles(question)
141
  if logic_answer is not None:
142
  return f"🧠 Logic Answer: {logic_answer}"
143
+ else:
144
+ riddle_guess = self.solve_riddle(question)
145
+ return f"🤖 Riddle Guess: {riddle_guess}"
146
 
147
  if video_path:
148
  transcription = self.call_whisper(video_path)