Update app.py
Browse files
app.py
CHANGED
@@ -13,7 +13,8 @@ import moviepy.editor as mp
|
|
13 |
from groq import Groq
|
14 |
from langchain_groq import ChatGroq
|
15 |
from langchain.agents import AgentExecutor, create_tool_calling_agent
|
16 |
-
|
|
|
17 |
from langchain_core.prompts import ChatPromptTemplate
|
18 |
from langchain.tools import Tool
|
19 |
|
@@ -77,7 +78,6 @@ class LangChainAgent:
|
|
77 |
def __init__(self, groq_api_key: str, tavily_api_key: str):
|
78 |
self.llm = ChatGroq(model_name="llama3-70b-8192", groq_api_key=groq_api_key, temperature=0.0)
|
79 |
|
80 |
-
# Updated tools with much more specific descriptions
|
81 |
self.tools = [
|
82 |
TavilySearchResults(
|
83 |
name="web_search",
|
@@ -97,7 +97,6 @@ class LangChainAgent:
|
|
97 |
),
|
98 |
]
|
99 |
|
100 |
-
# Updated, rule-based system prompt
|
101 |
prompt = ChatPromptTemplate.from_messages([
|
102 |
("system", (
|
103 |
"You are a powerful problem-solving agent. Your goal is to answer the user's question accurately. "
|
@@ -119,11 +118,10 @@ class LangChainAgent:
|
|
119 |
self.agent_executor = AgentExecutor(agent=agent, tools=self.tools, verbose=True, handle_parsing_errors=True)
|
120 |
|
121 |
def __call__(self, question: str, task_id: str) -> str:
|
122 |
-
# The agent sometimes needs the URL directly, so let's extract it if present.
|
123 |
urls = re.findall(r'https?://[^\s]+', question)
|
124 |
input_for_agent = {"input": question, "task_id": task_id}
|
125 |
if urls:
|
126 |
-
input_for_agent['video_url'] = urls[0]
|
127 |
|
128 |
try:
|
129 |
response = self.agent_executor.invoke(input_for_agent)
|
@@ -131,7 +129,7 @@ class LangChainAgent:
|
|
131 |
except Exception as e:
|
132 |
return f"Agent execution failed with an error: {e}"
|
133 |
|
134 |
-
# --- Main Application Logic
|
135 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
136 |
space_id = os.getenv("SPACE_ID")
|
137 |
if not profile: return "Please Login to Hugging Face with the button.", None
|
@@ -172,7 +170,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
172 |
return final_status, pd.DataFrame(results_log)
|
173 |
except Exception as e: return f"Submission Failed: {e}", pd.DataFrame(results_log)
|
174 |
|
175 |
-
# --- Gradio Interface
|
176 |
with gr.Blocks() as demo:
|
177 |
gr.Markdown("# Ultimate Agent Runner (Search + Audio + Video)")
|
178 |
gr.Markdown("This agent can search, transcribe audio files, and transcribe YouTube videos.")
|
|
|
13 |
from groq import Groq
|
14 |
from langchain_groq import ChatGroq
|
15 |
from langchain.agents import AgentExecutor, create_tool_calling_agent
|
16 |
+
# --- CORRECTED TAVILY IMPORT ---
|
17 |
+
from langchain_tavily import TavilySearchResults
|
18 |
from langchain_core.prompts import ChatPromptTemplate
|
19 |
from langchain.tools import Tool
|
20 |
|
|
|
78 |
def __init__(self, groq_api_key: str, tavily_api_key: str):
|
79 |
self.llm = ChatGroq(model_name="llama3-70b-8192", groq_api_key=groq_api_key, temperature=0.0)
|
80 |
|
|
|
81 |
self.tools = [
|
82 |
TavilySearchResults(
|
83 |
name="web_search",
|
|
|
97 |
),
|
98 |
]
|
99 |
|
|
|
100 |
prompt = ChatPromptTemplate.from_messages([
|
101 |
("system", (
|
102 |
"You are a powerful problem-solving agent. Your goal is to answer the user's question accurately. "
|
|
|
118 |
self.agent_executor = AgentExecutor(agent=agent, tools=self.tools, verbose=True, handle_parsing_errors=True)
|
119 |
|
120 |
def __call__(self, question: str, task_id: str) -> str:
|
|
|
121 |
urls = re.findall(r'https?://[^\s]+', question)
|
122 |
input_for_agent = {"input": question, "task_id": task_id}
|
123 |
if urls:
|
124 |
+
input_for_agent['video_url'] = urls[0]
|
125 |
|
126 |
try:
|
127 |
response = self.agent_executor.invoke(input_for_agent)
|
|
|
129 |
except Exception as e:
|
130 |
return f"Agent execution failed with an error: {e}"
|
131 |
|
132 |
+
# --- Main Application Logic ---
|
133 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
134 |
space_id = os.getenv("SPACE_ID")
|
135 |
if not profile: return "Please Login to Hugging Face with the button.", None
|
|
|
170 |
return final_status, pd.DataFrame(results_log)
|
171 |
except Exception as e: return f"Submission Failed: {e}", pd.DataFrame(results_log)
|
172 |
|
173 |
+
# --- Gradio Interface ---
|
174 |
with gr.Blocks() as demo:
|
175 |
gr.Markdown("# Ultimate Agent Runner (Search + Audio + Video)")
|
176 |
gr.Markdown("This agent can search, transcribe audio files, and transcribe YouTube videos.")
|