lovepreetsingh1996 commited on
Commit
17641af
·
1 Parent(s): 81917a3

feat: first try

Browse files
Files changed (2) hide show
  1. app.py +31 -1
  2. requirements.txt +7 -1
app.py CHANGED
@@ -2,6 +2,11 @@ import os
2
  import gradio as gr
3
  import requests
4
  import inspect
 
 
 
 
 
5
  import pandas as pd
6
 
7
  # (Keep Constants as is)
@@ -12,10 +17,35 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
12
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
13
  class BasicAgent:
14
  def __init__(self):
 
15
  print("BasicAgent initialized.")
16
  def __call__(self, question: str) -> str:
17
  print(f"Agent received question (first 50 chars): {question[:50]}...")
18
- fixed_answer = "This is a default answer."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  print(f"Agent returning fixed answer: {fixed_answer}")
20
  return fixed_answer
21
 
 
2
  import gradio as gr
3
  import requests
4
  import inspect
5
+ from llama_index.llms.huggingface_api import HuggingFaceInferenceAPI
6
+ from llama_index.readers.youtube_transcript import YoutubeTranscriptReader
7
+ from llama_index.core.tools import FunctionTool
8
+ from llama_index.tools.duckduckgo import DuckDuckGoSearchToolSpec
9
+ from llama_index.core.agent.workflow import AgentWorkflow
10
  import pandas as pd
11
 
12
  # (Keep Constants as is)
 
17
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
18
  class BasicAgent:
19
  def __init__(self):
20
+ self.llm = HuggingFaceInferenceAPI(model_name="Qwen/Qwen2.5-Coder-32B-Instruct")
21
  print("BasicAgent initialized.")
22
  def __call__(self, question: str) -> str:
23
  print(f"Agent received question (first 50 chars): {question[:50]}...")
24
+ def get_answers_from_youtube_transcript(youtube_link: str, query: str) -> str:
25
+ """Fetches transcript of the given youtube_link and returns matching answers based on query.
26
+ Args:
27
+ youtube_link (str): youtube video link for which we need to answer questions on.
28
+ query (str): question to answer from video transcript.
29
+ """
30
+ loader = YoutubeTranscriptReader()
31
+ documents = loader.load_data(
32
+ ytlinks=[youtube_link]
33
+ )
34
+
35
+ text = documents[0].text_resource.text
36
+
37
+ return "Here's the transcript from the video, examine and formulate answer based on what is said in the transcript: \n" + text
38
+
39
+ youtube_transcript_answer_tool = FunctionTool.from_defaults(
40
+ get_answers_from_youtube_transcript,
41
+ name="get_answers_from_youtube_transcript",
42
+ description="Fetches transcript of the given youtube_link and returns matching answers based on query.",
43
+ )
44
+
45
+ duckduckgoSearchTools = DuckDuckGoSearchToolSpec().to_tool_list()
46
+
47
+ agent = AgentWorkflow.from_tools_or_functions([*duckduckgoSearchTools, youtube_transcript_answer_tool], llm=self.llm)
48
+ fixed_answer = agent.run(question)
49
  print(f"Agent returning fixed answer: {fixed_answer}")
50
  return fixed_answer
51
 
requirements.txt CHANGED
@@ -1,2 +1,8 @@
1
  gradio
2
- requests
 
 
 
 
 
 
 
1
  gradio
2
+ requests
3
+ llama_index
4
+ llama_index-llms-ollama
5
+ llama_index-tools-duckduckgo
6
+ llama_index-readers-youtube_transcript
7
+ llama_index-retrievers-bm25
8
+ llama_index-llms-huggingface_api