Sonu313131 commited on
Commit
43ededf
·
verified ·
1 Parent(s): a7edfc4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -58
app.py CHANGED
@@ -15,61 +15,6 @@ openai_key = os.environ.get("OPENAI_API_KEY")
15
 
16
  search_tool = DuckDuckGoSearchTool()
17
 
18
- ##Tool 1
19
- from smolagents import Tool
20
- from youtube_transcript_api import YouTubeTranscriptApi
21
- from urllib.parse import urlparse, parse_qs
22
-
23
- from smolagents import Tool
24
- from youtube_transcript_api import YouTubeTranscriptApi
25
- from urllib.parse import urlparse, parse_qs
26
-
27
- class YouTubeDialogueTool(Tool):
28
- name = "youtube_dialogue_qa"
29
- description = "Extracts the transcript and finds what Teal'c says in response to a specific question."
30
-
31
- inputs = {
32
- "url": {
33
- "type": "string",
34
- "description": "Full YouTube video URL"
35
- },
36
- "question": {
37
- "type": "string",
38
- "description": 'Exact question asked (e.g., "Isn\'t that hot?")'
39
- },
40
- "speaker": {
41
- "type": "string",
42
- "description": "Name of the character who responds (e.g., 'Teal'c')",
43
- "nullable": True
44
- }
45
- }
46
-
47
- output_type = "string"
48
-
49
- def forward(self, url: str, question: str, speaker: str = "Teal'c") -> str:
50
- try:
51
- parsed = urlparse(url)
52
- video_id = parse_qs(parsed.query).get("v", [None])[0]
53
- if not video_id:
54
- return "ERROR: Invalid YouTube URL or missing video ID."
55
-
56
- transcript = YouTubeTranscriptApi.get_transcript(video_id)
57
-
58
- lines = [entry["text"].replace("\n", " ").strip() for entry in transcript if entry["text"].strip()]
59
-
60
- for idx, line in enumerate(lines):
61
- if question.lower().rstrip("?") in line.lower():
62
- if idx + 1 < len(lines):
63
- return lines[idx + 1].strip()
64
- break
65
-
66
- return "No response found in transcript."
67
-
68
- except Exception as e:
69
- return f"Error retrieving transcript: {str(e)}"
70
-
71
-
72
-
73
 
74
  ##Tool 2
75
  import wikipedia
@@ -130,7 +75,7 @@ class WikipediaQATool(Tool):
130
 
131
  wiki_tool = WikipediaQATool()
132
  #excel_tool = ExcelAnalysisTool()
133
- yt_tool = YouTubeDialogueTool()
134
 
135
  async def run_and_submit_all(profile: gr.OAuthProfile | None):
136
  log_output = ""
@@ -138,8 +83,8 @@ async def run_and_submit_all(profile: gr.OAuthProfile | None):
138
  try:
139
 
140
  agent = ToolCallingAgent(
141
- tools=[search_tool, yt_tool],
142
- model=OpenAIServerModel(model_id="gpt-4o-mini",
143
  api_key=os.environ["OPENAI_API_KEY"],
144
  temperature=0.0),
145
  max_steps=7,
 
15
 
16
  search_tool = DuckDuckGoSearchTool()
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  ##Tool 2
20
  import wikipedia
 
75
 
76
  wiki_tool = WikipediaQATool()
77
  #excel_tool = ExcelAnalysisTool()
78
+ #yt_tool = YouTubeDialogueTool()
79
 
80
  async def run_and_submit_all(profile: gr.OAuthProfile | None):
81
  log_output = ""
 
83
  try:
84
 
85
  agent = ToolCallingAgent(
86
+ tools=[search_tool],
87
+ model=OpenAIServerModel(model_id="gpt-4o",
88
  api_key=os.environ["OPENAI_API_KEY"],
89
  temperature=0.0),
90
  max_steps=7,