Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -36,7 +36,7 @@ from langgraph.graph import StateGraph, END
|
|
36 |
from langchain_community.llms import HuggingFacePipeline
|
37 |
|
38 |
# Corrected Tool import: Use 'tool' (lowercase)
|
39 |
-
from langchain_core.tools import BaseTool, tool
|
40 |
|
41 |
# Hugging Face local model imports
|
42 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
@@ -55,7 +55,7 @@ def indent_code(code: str, indent: str = " ") -> str:
|
|
55 |
return "\n".join(indent + line for line in code.splitlines())
|
56 |
|
57 |
# --- Tool Definitions ---
|
58 |
-
@tool
|
59 |
def duckduckgo_search(query: str) -> str:
|
60 |
"""Search web using DuckDuckGo. Returns top 3 results."""
|
61 |
print(f"DEBUG: duckduckgo_search called with: {query}")
|
@@ -68,7 +68,7 @@ def duckduckgo_search(query: str) -> str:
|
|
68 |
except Exception as e:
|
69 |
return f"Error performing DuckDuckGo search: {str(e)}"
|
70 |
|
71 |
-
@tool
|
72 |
def wikipedia_search(query: str) -> str:
|
73 |
"""Get Wikipedia summaries. Returns first 3 sentences."""
|
74 |
print(f"DEBUG: wikipedia_search called with: {query}")
|
@@ -81,7 +81,7 @@ def wikipedia_search(query: str) -> str:
|
|
81 |
except Exception as e:
|
82 |
return f"Error performing Wikipedia search: {str(e)}"
|
83 |
|
84 |
-
@tool
|
85 |
def arxiv_search(query: str) -> str:
|
86 |
"""Search academic papers on arXiv. Returns top 3 results."""
|
87 |
print(f"DEBUG: arxiv_search called with: {query}")
|
@@ -100,7 +100,7 @@ def arxiv_search(query: str) -> str:
|
|
100 |
except Exception as e:
|
101 |
return f"Error performing ArXiv search: {str(e)}"
|
102 |
|
103 |
-
@tool
|
104 |
def document_qa(input_str: str) -> str:
|
105 |
"""Answer questions from documents. Input format: 'document_text||question'"""
|
106 |
print(f"DEBUG: document_qa called with: {input_str}")
|
@@ -117,17 +117,17 @@ def document_qa(input_str: str) -> str:
|
|
117 |
except Exception as e:
|
118 |
return f"Error answering question from document: {str(e)}"
|
119 |
|
120 |
-
@tool
|
121 |
def python_execution(code: str) -> str:
|
122 |
"""Execute Python code and return output.
|
123 |
-
The code should assign its final result to a variable named '
|
124 |
-
Example: '
|
125 |
"""
|
126 |
print(f"DEBUG: python_execution called with: {code}")
|
127 |
try:
|
128 |
# Create isolated environment
|
129 |
env = {}
|
130 |
-
# Wrap code in a function to isolate scope and capture '
|
131 |
# The exec function is used carefully here. In a production environment,
|
132 |
# consider a more robust and secure sandbox (e.g., Docker, dedicated service).
|
133 |
exec(f"def __exec_fn__():\n{indent_code(code)}\n_result_value = __exec_fn__()", globals(), env)
|
@@ -137,7 +137,8 @@ def python_execution(code: str) -> str:
|
|
137 |
|
138 |
class VideoTranscriptionTool(BaseTool):
|
139 |
name: str = "transcript_video"
|
140 |
-
|
|
|
141 |
|
142 |
def _run(self, url_or_id: str) -> str:
|
143 |
print(f"DEBUG: transcript_video called with: {url_or_id}")
|
@@ -531,6 +532,7 @@ class BasicAgent:
|
|
531 |
|
532 |
|
533 |
|
|
|
534 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
535 |
"""
|
536 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
|
|
36 |
from langchain_community.llms import HuggingFacePipeline
|
37 |
|
38 |
# Corrected Tool import: Use 'tool' (lowercase)
|
39 |
+
from langchain_core.tools import BaseTool, tool
|
40 |
|
41 |
# Hugging Face local model imports
|
42 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
|
|
55 |
return "\n".join(indent + line for line in code.splitlines())
|
56 |
|
57 |
# --- Tool Definitions ---
|
58 |
+
@tool
|
59 |
def duckduckgo_search(query: str) -> str:
|
60 |
"""Search web using DuckDuckGo. Returns top 3 results."""
|
61 |
print(f"DEBUG: duckduckgo_search called with: {query}")
|
|
|
68 |
except Exception as e:
|
69 |
return f"Error performing DuckDuckGo search: {str(e)}"
|
70 |
|
71 |
+
@tool
|
72 |
def wikipedia_search(query: str) -> str:
|
73 |
"""Get Wikipedia summaries. Returns first 3 sentences."""
|
74 |
print(f"DEBUG: wikipedia_search called with: {query}")
|
|
|
81 |
except Exception as e:
|
82 |
return f"Error performing Wikipedia search: {str(e)}"
|
83 |
|
84 |
+
@tool
|
85 |
def arxiv_search(query: str) -> str:
|
86 |
"""Search academic papers on arXiv. Returns top 3 results."""
|
87 |
print(f"DEBUG: arxiv_search called with: {query}")
|
|
|
100 |
except Exception as e:
|
101 |
return f"Error performing ArXiv search: {str(e)}"
|
102 |
|
103 |
+
@tool
|
104 |
def document_qa(input_str: str) -> str:
|
105 |
"""Answer questions from documents. Input format: 'document_text||question'"""
|
106 |
print(f"DEBUG: document_qa called with: {input_str}")
|
|
|
117 |
except Exception as e:
|
118 |
return f"Error answering question from document: {str(e)}"
|
119 |
|
120 |
+
@tool
|
121 |
def python_execution(code: str) -> str:
|
122 |
"""Execute Python code and return output.
|
123 |
+
The code should assign its final result to a variable named '_result_value'.
|
124 |
+
Example: '_result_value = 1 + 1'
|
125 |
"""
|
126 |
print(f"DEBUG: python_execution called with: {code}")
|
127 |
try:
|
128 |
# Create isolated environment
|
129 |
env = {}
|
130 |
+
# Wrap code in a function to isolate scope and capture '_result_value'
|
131 |
# The exec function is used carefully here. In a production environment,
|
132 |
# consider a more robust and secure sandbox (e.g., Docker, dedicated service).
|
133 |
exec(f"def __exec_fn__():\n{indent_code(code)}\n_result_value = __exec_fn__()", globals(), env)
|
|
|
137 |
|
138 |
class VideoTranscriptionTool(BaseTool):
|
139 |
name: str = "transcript_video"
|
140 |
+
# CORRECTED LINE BELOW: Added '=' for assignment
|
141 |
+
description: str = "Fetch text transcript from YouTube videos using URL or ID. Use for any question involving video or audio. Input is the YouTube URL or ID."
|
142 |
|
143 |
def _run(self, url_or_id: str) -> str:
|
144 |
print(f"DEBUG: transcript_video called with: {url_or_id}")
|
|
|
532 |
|
533 |
|
534 |
|
535 |
+
|
536 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
537 |
"""
|
538 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|