Quazim0t0 commited on
Commit
9b69859
·
verified ·
1 Parent(s): a07c74e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -28
app.py CHANGED
@@ -8,7 +8,6 @@ import os
8
  import gradio as gr
9
  from smolagents import CodeAgent, HfApiModel, tool
10
  from typing import Dict, List, Optional, Tuple, Union
11
- import json
12
 
13
  # Advanced Research Tools
14
  @tool
@@ -40,19 +39,10 @@ def web_search(query: str, max_results: int = 5) -> str:
40
 
41
  @tool
42
  def analyze_content(text: str, analysis_type: str = "general") -> str:
43
- """Analyzes content for various aspects like key points, themes, or citations
44
-
45
- Args:
46
- text: The content to analyze
47
- analysis_type: Type of analysis ("general", "academic", "citations")
48
-
49
- Returns:
50
- str: Analysis results in a structured format
51
- """
52
  points = []
53
 
54
  if "academic" in analysis_type.lower():
55
- # Academic analysis focusing on scholarly aspects
56
  points.extend([
57
  "Key Arguments:",
58
  "- Main thesis and supporting evidence",
@@ -63,7 +53,6 @@ def analyze_content(text: str, analysis_type: str = "general") -> str:
63
  "- Research foundations",
64
  ])
65
  elif "citations" in analysis_type.lower():
66
- # Citation analysis
67
  points.extend([
68
  "Citation Analysis:",
69
  "- Author credentials",
@@ -74,7 +63,6 @@ def analyze_content(text: str, analysis_type: str = "general") -> str:
74
  "- Secondary references",
75
  ])
76
  else:
77
- # General content analysis
78
  points.extend([
79
  "Content Overview:",
80
  "- Main topics and themes",
@@ -137,7 +125,8 @@ class ResearchSystem:
137
  chat = gr.Chatbot(
138
  label="Research Process",
139
  height=600,
140
- show_label=True
 
141
  )
142
 
143
  with gr.Column(scale=1):
@@ -181,11 +170,13 @@ class ResearchSystem:
181
  outputs=[chat]
182
  )
183
 
 
 
 
 
184
  clear_btn.click(
185
- lambda: None,
186
- inputs=[],
187
- outputs=[chat],
188
- _js="() => []" # Clear chat
189
  )
190
 
191
  # Help information
@@ -206,7 +197,7 @@ class ResearchSystem:
206
  def process_query(self,
207
  query: str,
208
  depth: int = 3,
209
- num_sources: int = 5) -> List[List[str]]:
210
  """
211
  Processes a research query with enhanced capabilities
212
 
@@ -216,16 +207,16 @@ class ResearchSystem:
216
  num_sources: Number of sources to include (1-10)
217
 
218
  Returns:
219
- List of message pairs for the chatbot interface
220
  """
221
  try:
222
  # Check cache first
223
  if query in self.cache and self.config["cache_results"]:
224
  raw_research, formatted = self.cache[query]
225
  return [
226
- [query, None],
227
- ["Researcher (Cached)", raw_research],
228
- ["Formatter (Cached)", formatted]
229
  ]
230
 
231
  # Configure research parameters
@@ -256,11 +247,11 @@ class ResearchSystem:
256
  if self.config["cache_results"]:
257
  self.cache[query] = (raw_research, formatted)
258
 
259
- # Return results in chatbot format
260
  return [
261
- [query, None],
262
- ["📚 Research Findings", raw_research],
263
- ["📝 MLA Formatted", formatted]
264
  ]
265
 
266
  except Exception as e:
@@ -268,7 +259,7 @@ class ResearchSystem:
268
  f"Error during research process: {str(e)}\n"
269
  "Please try again or refine your query."
270
  )
271
- return [[None, error_msg]]
272
 
273
  if __name__ == "__main__":
274
  system = ResearchSystem()
 
8
  import gradio as gr
9
  from smolagents import CodeAgent, HfApiModel, tool
10
  from typing import Dict, List, Optional, Tuple, Union
 
11
 
12
  # Advanced Research Tools
13
  @tool
 
39
 
40
  @tool
41
  def analyze_content(text: str, analysis_type: str = "general") -> str:
42
+ """Analyzes content for various aspects like key points, themes, or citations"""
 
 
 
 
 
 
 
 
43
  points = []
44
 
45
  if "academic" in analysis_type.lower():
 
46
  points.extend([
47
  "Key Arguments:",
48
  "- Main thesis and supporting evidence",
 
53
  "- Research foundations",
54
  ])
55
  elif "citations" in analysis_type.lower():
 
56
  points.extend([
57
  "Citation Analysis:",
58
  "- Author credentials",
 
63
  "- Secondary references",
64
  ])
65
  else:
 
66
  points.extend([
67
  "Content Overview:",
68
  "- Main topics and themes",
 
125
  chat = gr.Chatbot(
126
  label="Research Process",
127
  height=600,
128
+ show_label=True,
129
+ type="messages" # Use new message format
130
  )
131
 
132
  with gr.Column(scale=1):
 
170
  outputs=[chat]
171
  )
172
 
173
+ # Clear chat using the proper method
174
+ def clear_chat():
175
+ return None
176
+
177
  clear_btn.click(
178
+ clear_chat,
179
+ outputs=[chat]
 
 
180
  )
181
 
182
  # Help information
 
197
  def process_query(self,
198
  query: str,
199
  depth: int = 3,
200
+ num_sources: int = 5) -> List[Dict[str, str]]:
201
  """
202
  Processes a research query with enhanced capabilities
203
 
 
207
  num_sources: Number of sources to include (1-10)
208
 
209
  Returns:
210
+ List of message dictionaries for the chatbot interface
211
  """
212
  try:
213
  # Check cache first
214
  if query in self.cache and self.config["cache_results"]:
215
  raw_research, formatted = self.cache[query]
216
  return [
217
+ {"role": "user", "content": query},
218
+ {"role": "assistant", "content": f"📚 Research Findings:\n{raw_research}"},
219
+ {"role": "assistant", "content": f"📝 MLA Formatted:\n{formatted}"}
220
  ]
221
 
222
  # Configure research parameters
 
247
  if self.config["cache_results"]:
248
  self.cache[query] = (raw_research, formatted)
249
 
250
+ # Return results in new message format
251
  return [
252
+ {"role": "user", "content": query},
253
+ {"role": "assistant", "content": f"📚 Research Findings:\n{raw_research}"},
254
+ {"role": "assistant", "content": f"📝 MLA Formatted:\n{formatted}"}
255
  ]
256
 
257
  except Exception as e:
 
259
  f"Error during research process: {str(e)}\n"
260
  "Please try again or refine your query."
261
  )
262
+ return [{"role": "assistant", "content": error_msg}]
263
 
264
  if __name__ == "__main__":
265
  system = ResearchSystem()