AmineLemsih commited on
Commit
daf1b42
·
verified ·
1 Parent(s): 5952546

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -31
app.py CHANGED
@@ -1,64 +1,40 @@
1
- from smolagents import CodeAgent,tool, DuckDuckGoSearchTool, HfApiModel,load_tool
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:
50
- """A tool that fetches the current local time in a specified timezone.
51
- Args:
52
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
53
- """
54
  try:
55
- # Create timezone object
56
  tz = pytz.timezone(timezone)
57
- # Get current time in that timezone
58
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
59
  return f"The current local time in {timezone} is: {local_time}"
60
  except Exception as e:
61
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
62
 
63
  # ---------- AGENT ----------
64
 
 
1
+ from smolagents import CodeAgent, tool, HfApiModel, load_tool
2
+ from youtube_transcript_api import YouTubeTranscriptApi
3
+ import datetime, pytz, yaml, re
 
 
 
4
  from tools.final_answer import FinalAnswerTool
 
5
  from Gradio_UI import GradioUI
6
 
7
  # ---------- TOOLS ----------
8
  @tool
9
  def get_transcript(url: str) -> str:
 
 
 
 
 
 
10
  video_id = re.search(r"(?:v=|youtu\.be/)([^&\n?#]+)", url)
11
  if not video_id:
12
  return "Impossible de détecter l’ID vidéo."
13
  video_id = video_id.group(1)
14
 
15
  try:
16
+ transcript = YouTubeTranscriptApi.get_transcript(video_id, languages=['fr', 'en'])
 
17
  return " ".join(seg["text"] for seg in transcript)
18
  except Exception as e:
19
+ return f"Erreur transcript : {e}"
20
 
21
  @tool
22
  def summarize(text: str, max_chars: int = 1500) -> str:
 
 
 
 
 
 
 
23
  snippet = text[:max_chars]
24
  prompt = (
25
  "Résume le texte suivant en 8‑10 bullet points clairs :\n\n"
26
  f"{snippet}\n\n# Résumé :"
27
  )
28
+ return prompt
29
 
30
  @tool
31
  def get_current_time_in_timezone(timezone: str) -> str:
 
 
 
 
32
  try:
 
33
  tz = pytz.timezone(timezone)
 
34
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
35
  return f"The current local time in {timezone} is: {local_time}"
36
  except Exception as e:
37
+ return f"Error fetching time: {str(e)}"
38
 
39
  # ---------- AGENT ----------
40