AmineLemsih commited on
Commit
fc5a09d
·
verified ·
1 Parent(s): 8c5c24b

Ajout de l'agent résumé YouTube

Browse files

- Ajout des outils get_transcript et summarize
- Configuration de l’agent Hugging Face smolagents
- Utilise Qwen2.5-Coder-32B-Instruct pour générer le résumé

Files changed (1) hide show
  1. app.py +38 -10
app.py CHANGED
@@ -1,22 +1,49 @@
1
- from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
 
2
  import datetime
3
  import requests
4
  import pytz
5
- import yaml
6
  from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
9
 
10
- # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -33,6 +60,7 @@ def get_current_time_in_timezone(timezone: str) -> str:
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
 
36
 
37
  final_answer = FinalAnswerTool()
38
 
@@ -55,7 +83,7 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
1
+ from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool, toolInferenceClientModel
2
+ from youtube_transcript_api import YouTubeTranscriptApi # pip install youtube-transcript-api
3
  import datetime
4
  import requests
5
  import pytz
6
+ import yaml, textwrap, re
7
  from tools.final_answer import FinalAnswerTool
8
 
9
  from Gradio_UI import GradioUI
10
 
11
+ # ---------- TOOLS ----------
12
  @tool
13
+ def get_transcript(url: str) -> str:
14
+ """
15
+ Télécharge la transcription (FR ou EN) d’une vidéo YouTube.
16
+ Args:
17
+ url: lien complet YouTube
18
+ """
19
+ # extraction robuste de l’ID
20
+ video_id = re.search(r"(?:v=|youtu\.be/)([^&\n?#]+)", url)
21
+ if not video_id:
22
+ return "Impossible de détecter l’ID vidéo."
23
+ video_id = video_id.group(1)
24
+
25
+ try:
26
+ transcript = YouTubeTranscriptApi.get_transcript(
27
+ video_id, languages=['fr', 'en'])
28
+ return " ".join(seg["text"] for seg in transcript)
29
+ except Exception as e:
30
+ return f"Erreur transcript : {e}"
31
+
32
+ @tool
33
+ def summarize(text: str, max_chars: int = 1500) -> str:
34
+ """
35
+ Résume le texte en ~10 bullet points (Markdown).
36
  Args:
37
+ text: transcription brute
38
+ max_chars: longueur max passée au LLM
39
  """
40
+ # coupe si trop long pour le contexte
41
+ snippet = text[:max_chars]
42
+ prompt = (
43
+ "Résume le texte suivant en 8‑10 bullet points clairs :\n\n"
44
+ f"{snippet}\n\n# Résumé :"
45
+ )
46
+ return prompt # on renvoie le prompt ; l’agent fera l’appel LLM
47
 
48
  @tool
49
  def get_current_time_in_timezone(timezone: str) -> str:
 
60
  except Exception as e:
61
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
62
 
63
+ # ---------- AGENT ----------
64
 
65
  final_answer = FinalAnswerTool()
66
 
 
83
 
84
  agent = CodeAgent(
85
  model=model,
86
+ tools=tools=[final_answer, get_transcript, summarize], ## add your tools here (don't remove final answer)
87
  max_steps=6,
88
  verbosity_level=1,
89
  grammar=None,