Spaces:
Sleeping
Sleeping
Commit ·
872fb01
1
Parent(s): 8e63348
modified process_attachment
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import requests
|
|
| 4 |
import tempfile
|
| 5 |
import mimetypes
|
| 6 |
import base64
|
|
|
|
| 7 |
import pandas as pd
|
| 8 |
import datetime
|
| 9 |
from langchain.tools import tool
|
|
@@ -270,14 +271,19 @@ def python_executor(code: str) -> str:
|
|
| 270 |
|
| 271 |
# --- TOOL 15: Attachment Processing Tool ---
|
| 272 |
@tool
|
| 273 |
-
def process_attachment(
|
| 274 |
"""
|
| 275 |
-
Processes an input attachment (audio, image, or video) and returns extracted text or a summary suitable for LLM input.
|
| 276 |
-
|
| 277 |
-
- For image: encodes as base64 and returns a prompt for LLMs that support image input.
|
| 278 |
-
- For video: extracts audio, transcribes, and returns the transcript.
|
| 279 |
-
- For unsupported types: returns an error message.
|
| 280 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
# Detect file type
|
| 282 |
mime_type, _ = mimetypes.guess_type(filename)
|
| 283 |
if not mime_type:
|
|
|
|
| 4 |
import tempfile
|
| 5 |
import mimetypes
|
| 6 |
import base64
|
| 7 |
+
import json
|
| 8 |
import pandas as pd
|
| 9 |
import datetime
|
| 10 |
from langchain.tools import tool
|
|
|
|
| 271 |
|
| 272 |
# --- TOOL 15: Attachment Processing Tool ---
|
| 273 |
@tool
|
| 274 |
+
def process_attachment(input_str: str) -> str:
|
| 275 |
"""
|
| 276 |
+
Processes an input attachment (audio, image, or video) and returns extracted text or a summary suitable for LLM input.
|
| 277 |
+
This function accepts a JSON string with keys: 'file_bytes' (base64), and 'filename'. For unsupported file types the function returns an error message.
|
|
|
|
|
|
|
|
|
|
| 278 |
"""
|
| 279 |
+
|
| 280 |
+
try:
|
| 281 |
+
data = json.loads(input_str)
|
| 282 |
+
file_bytes = base64.b64decode(data["file_bytes"])
|
| 283 |
+
filename = data["filename"]
|
| 284 |
+
except Exception as e:
|
| 285 |
+
return f"error: {e}"
|
| 286 |
+
|
| 287 |
# Detect file type
|
| 288 |
mime_type, _ = mimetypes.guess_type(filename)
|
| 289 |
if not mime_type:
|