Spaces:
Sleeping
Sleeping
Update tools/tools.py
Browse files- tools/tools.py +14 -5
tools/tools.py
CHANGED
|
@@ -8,6 +8,11 @@ from dotenv import load_dotenv
|
|
| 8 |
|
| 9 |
load_dotenv()
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
@tool
|
| 12 |
def vision_tool(prompt: str, image_list: list) -> str:
|
| 13 |
"""
|
|
@@ -20,7 +25,9 @@ def vision_tool(prompt: str, image_list: list) -> str:
|
|
| 20 |
"""
|
| 21 |
import io, base64, os
|
| 22 |
from smolagents import OpenAIServerModel
|
| 23 |
-
from PIL import Image
|
|
|
|
|
|
|
| 24 |
|
| 25 |
model = OpenAIServerModel(
|
| 26 |
model_id='gemma4:31b-cloud',
|
|
@@ -45,7 +52,6 @@ def vision_tool(prompt: str, image_list: list) -> str:
|
|
| 45 |
# ----------------------------------------------------------------------------
|
| 46 |
# SECTION 2: YouTube Pipeline (Tout-en-un pour la robustesse)
|
| 47 |
# ----------------------------------------------------------------------------
|
| 48 |
-
@spaces.GPU(duration=20)
|
| 49 |
@tool
|
| 50 |
def ask_youtube_full_pipeline(url: str, question: str) -> str:
|
| 51 |
"""
|
|
@@ -59,6 +65,8 @@ def ask_youtube_full_pipeline(url: str, question: str) -> str:
|
|
| 59 |
from PIL import Image
|
| 60 |
from smolagents import OpenAIServerModel
|
| 61 |
|
|
|
|
|
|
|
| 62 |
# 1. Extraction ID interne
|
| 63 |
patterns = [r"v=([a-zA-Z0-9_-]{11})", r"youtu\.be/([a-zA-Z0-9_-]{11})"]
|
| 64 |
video_id = None
|
|
@@ -109,7 +117,6 @@ def ask_youtube_full_pipeline(url: str, question: str) -> str:
|
|
| 109 |
# ----------------------------------------------------------------------------
|
| 110 |
# SECTION 3: Fichiers & Audio
|
| 111 |
# ----------------------------------------------------------------------------
|
| 112 |
-
@spaces.GPU(duration=10)
|
| 113 |
@tool
|
| 114 |
def read_pdf_file(file_path: str) -> str:
|
| 115 |
"""
|
|
@@ -120,6 +127,8 @@ def read_pdf_file(file_path: str) -> str:
|
|
| 120 |
"""
|
| 121 |
import os
|
| 122 |
from pypdf import PdfReader
|
|
|
|
|
|
|
| 123 |
|
| 124 |
if not os.path.exists(file_path):
|
| 125 |
return f"Erreur : Le fichier au chemin '{file_path}' est introuvable."
|
|
@@ -141,7 +150,6 @@ def read_pdf_file(file_path: str) -> str:
|
|
| 141 |
except Exception as e:
|
| 142 |
return f"Erreur lors de la lecture du fichier PDF : {str(e)}"
|
| 143 |
|
| 144 |
-
@spaces.GPU(duration=10)
|
| 145 |
@tool
|
| 146 |
def read_docx_file(file_path: str) -> str:
|
| 147 |
"""
|
|
@@ -152,6 +160,8 @@ def read_docx_file(file_path: str) -> str:
|
|
| 152 |
"""
|
| 153 |
import docx
|
| 154 |
import os
|
|
|
|
|
|
|
| 155 |
|
| 156 |
if not os.path.exists(file_path):
|
| 157 |
return f"Erreur : Le fichier au chemin '{file_path}' est introuvable."
|
|
@@ -324,7 +334,6 @@ def extract_text_via_ocr(image_path: str) -> str:
|
|
| 324 |
except Exception as e:
|
| 325 |
return f"Erreur lors de l'appel API OCR : {str(e)}"
|
| 326 |
|
| 327 |
-
@spaces.GPU(duration=20)
|
| 328 |
@tool
|
| 329 |
def summarize_csv_data(path: str, query: str = "") -> str:
|
| 330 |
"""
|
|
|
|
| 8 |
|
| 9 |
load_dotenv()
|
| 10 |
|
| 11 |
+
|
| 12 |
+
@spaces.GPU(duration=20)
|
| 13 |
+
def initialize_gpu() :
|
| 14 |
+
return 0
|
| 15 |
+
|
| 16 |
@tool
|
| 17 |
def vision_tool(prompt: str, image_list: list) -> str:
|
| 18 |
"""
|
|
|
|
| 25 |
"""
|
| 26 |
import io, base64, os
|
| 27 |
from smolagents import OpenAIServerModel
|
| 28 |
+
from PIL import Image
|
| 29 |
+
|
| 30 |
+
initialize_gpu()
|
| 31 |
|
| 32 |
model = OpenAIServerModel(
|
| 33 |
model_id='gemma4:31b-cloud',
|
|
|
|
| 52 |
# ----------------------------------------------------------------------------
|
| 53 |
# SECTION 2: YouTube Pipeline (Tout-en-un pour la robustesse)
|
| 54 |
# ----------------------------------------------------------------------------
|
|
|
|
| 55 |
@tool
|
| 56 |
def ask_youtube_full_pipeline(url: str, question: str) -> str:
|
| 57 |
"""
|
|
|
|
| 65 |
from PIL import Image
|
| 66 |
from smolagents import OpenAIServerModel
|
| 67 |
|
| 68 |
+
initialize_gpu()
|
| 69 |
+
|
| 70 |
# 1. Extraction ID interne
|
| 71 |
patterns = [r"v=([a-zA-Z0-9_-]{11})", r"youtu\.be/([a-zA-Z0-9_-]{11})"]
|
| 72 |
video_id = None
|
|
|
|
| 117 |
# ----------------------------------------------------------------------------
|
| 118 |
# SECTION 3: Fichiers & Audio
|
| 119 |
# ----------------------------------------------------------------------------
|
|
|
|
| 120 |
@tool
|
| 121 |
def read_pdf_file(file_path: str) -> str:
|
| 122 |
"""
|
|
|
|
| 127 |
"""
|
| 128 |
import os
|
| 129 |
from pypdf import PdfReader
|
| 130 |
+
|
| 131 |
+
initialize_gpu()
|
| 132 |
|
| 133 |
if not os.path.exists(file_path):
|
| 134 |
return f"Erreur : Le fichier au chemin '{file_path}' est introuvable."
|
|
|
|
| 150 |
except Exception as e:
|
| 151 |
return f"Erreur lors de la lecture du fichier PDF : {str(e)}"
|
| 152 |
|
|
|
|
| 153 |
@tool
|
| 154 |
def read_docx_file(file_path: str) -> str:
|
| 155 |
"""
|
|
|
|
| 160 |
"""
|
| 161 |
import docx
|
| 162 |
import os
|
| 163 |
+
|
| 164 |
+
initialize_gpu()
|
| 165 |
|
| 166 |
if not os.path.exists(file_path):
|
| 167 |
return f"Erreur : Le fichier au chemin '{file_path}' est introuvable."
|
|
|
|
| 334 |
except Exception as e:
|
| 335 |
return f"Erreur lors de l'appel API OCR : {str(e)}"
|
| 336 |
|
|
|
|
| 337 |
@tool
|
| 338 |
def summarize_csv_data(path: str, query: str = "") -> str:
|
| 339 |
"""
|