n0v33n commited on
Commit ·
bcfe4cb
1
Parent(s): f8d598a
Resolving Timeout error
Browse files- Dockerfile +2 -20
- agent.py +3 -36
- app.py +28 -23
- requirements.txt +0 -2
Dockerfile
CHANGED
|
@@ -1,35 +1,17 @@
|
|
| 1 |
-
# Use the official Python slim image as the base image
|
| 2 |
FROM python:3.12-slim
|
| 3 |
-
|
| 4 |
-
# Set the working directory in the container
|
| 5 |
WORKDIR /app
|
| 6 |
-
|
| 7 |
-
# Update pip to the latest version
|
| 8 |
RUN pip install --upgrade pip
|
| 9 |
-
|
| 10 |
-
# Install build dependencies for compiling Python packages
|
| 11 |
RUN apt-get update && apt-get install -y \
|
| 12 |
gcc \
|
| 13 |
g++ \
|
| 14 |
libffi-dev \
|
| 15 |
libssl-dev \
|
| 16 |
python3-dev \
|
|
|
|
| 17 |
&& rm -rf /var/lib/apt/lists/*
|
| 18 |
-
|
| 19 |
-
# Copy the requirements.txt file into the container
|
| 20 |
COPY requirements.txt .
|
| 21 |
-
|
| 22 |
-
# Verify that requirements.txt exists (for debugging)
|
| 23 |
-
RUN ls -la /app && test -f /app/requirements.txt || (echo "Error: requirements.txt not found in /app" && exit 1)
|
| 24 |
-
|
| 25 |
-
# Install Python dependencies from requirements.txt
|
| 26 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 27 |
-
|
| 28 |
-
# Copy the application code into the container
|
| 29 |
COPY . .
|
| 30 |
-
|
| 31 |
-
# Expose the port Gradio will run on (default is 7860)
|
| 32 |
EXPOSE 7860
|
| 33 |
-
|
| 34 |
-
# Command to run the Gradio app
|
| 35 |
CMD ["python", "app.py"]
|
|
|
|
|
|
|
| 1 |
FROM python:3.12-slim
|
|
|
|
|
|
|
| 2 |
WORKDIR /app
|
|
|
|
|
|
|
| 3 |
RUN pip install --upgrade pip
|
|
|
|
|
|
|
| 4 |
RUN apt-get update && apt-get install -y \
|
| 5 |
gcc \
|
| 6 |
g++ \
|
| 7 |
libffi-dev \
|
| 8 |
libssl-dev \
|
| 9 |
python3-dev \
|
| 10 |
+
libespeak1 \
|
| 11 |
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
+
RUN mkdir -p /tmp && chmod 777 /tmp
|
|
|
|
| 13 |
COPY requirements.txt .
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
RUN pip install --no-cache-dir -r requirements.txt
|
|
|
|
|
|
|
| 15 |
COPY . .
|
|
|
|
|
|
|
| 16 |
EXPOSE 7860
|
|
|
|
|
|
|
| 17 |
CMD ["python", "app.py"]
|
agent.py
CHANGED
|
@@ -26,52 +26,19 @@ class AnalysisDescription(BaseModel):
|
|
| 26 |
MODEL = "mistral-medium-latest"
|
| 27 |
|
| 28 |
def play_wav(url: str, save_path: str = "/tmp/audio.wav"):
|
| 29 |
-
"""
|
| 30 |
-
Plays a WAV file from a URL or local file path.
|
| 31 |
-
Args:
|
| 32 |
-
url (str): URL or file path (e.g., file://path/to/file.wav).
|
| 33 |
-
save_path (str, optional): Path to save downloaded files. Defaults to "/tmp/audio.wav".
|
| 34 |
-
Returns:
|
| 35 |
-
str: Status message
|
| 36 |
-
"""
|
| 37 |
try:
|
| 38 |
-
# Handle local file paths
|
| 39 |
if url.startswith("file://"):
|
| 40 |
file_path = urllib.parse.urlparse(url).path
|
| 41 |
-
|
| 42 |
-
# On Windows, remove leading slash AND decode percent-encoding
|
| 43 |
-
file_path = urllib.parse.unquote(file_path.lstrip("/"))
|
| 44 |
-
else:
|
| 45 |
-
file_path = urllib.parse.unquote(file_path)
|
| 46 |
-
print(f"Playing local file: {file_path}")
|
| 47 |
else:
|
| 48 |
-
# Download from URL
|
| 49 |
-
print(f"Attempting to download WAV file from {url}...")
|
| 50 |
response = requests.get(url, timeout=10)
|
| 51 |
response.raise_for_status()
|
| 52 |
-
|
| 53 |
with open(save_path, 'wb') as f:
|
| 54 |
f.write(response.content)
|
| 55 |
-
print(f"WAV file successfully downloaded and saved to {save_path}")
|
| 56 |
file_path = save_path
|
| 57 |
-
|
| 58 |
-
print(f"Attempting to play {file_path}...")
|
| 59 |
-
try:
|
| 60 |
-
# Jupyter playback
|
| 61 |
-
display(Audio(filename=file_path))
|
| 62 |
-
except NameError:
|
| 63 |
-
# Non-Jupyter playback
|
| 64 |
-
if platform.system() == "Windows":
|
| 65 |
-
os.startfile(file_path)
|
| 66 |
-
elif platform.system() == "Darwin": # macOS
|
| 67 |
-
subprocess.run(["open", file_path], check=True)
|
| 68 |
-
else: # Linux
|
| 69 |
-
subprocess.run(["xdg-open", file_path], check=True)
|
| 70 |
-
|
| 71 |
-
return "Audio played successfully"
|
| 72 |
-
|
| 73 |
except Exception as e:
|
| 74 |
-
print(f"Error
|
| 75 |
return f"Error: {str(e)}"
|
| 76 |
|
| 77 |
# Create DocAgent for OCR PDF processing
|
|
|
|
| 26 |
MODEL = "mistral-medium-latest"
|
| 27 |
|
| 28 |
def play_wav(url: str, save_path: str = "/tmp/audio.wav"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
try:
|
|
|
|
| 30 |
if url.startswith("file://"):
|
| 31 |
file_path = urllib.parse.urlparse(url).path
|
| 32 |
+
file_path = urllib.parse.unquote(file_path.lstrip("/"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
else:
|
|
|
|
|
|
|
| 34 |
response = requests.get(url, timeout=10)
|
| 35 |
response.raise_for_status()
|
|
|
|
| 36 |
with open(save_path, 'wb') as f:
|
| 37 |
f.write(response.content)
|
|
|
|
| 38 |
file_path = save_path
|
| 39 |
+
return file_path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
except Exception as e:
|
| 41 |
+
print(f"Error handling audio: {str(e)}")
|
| 42 |
return f"Error: {str(e)}"
|
| 43 |
|
| 44 |
# Create DocAgent for OCR PDF processing
|
app.py
CHANGED
|
@@ -3,13 +3,35 @@ import asyncio
|
|
| 3 |
import json
|
| 4 |
import os
|
| 5 |
import base64
|
| 6 |
-
from agent import (
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
from mistralai import Mistral
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
custom_css = """
|
| 15 |
body {
|
|
@@ -46,23 +68,6 @@ input, textarea, select {
|
|
| 46 |
}
|
| 47 |
"""
|
| 48 |
|
| 49 |
-
|
| 50 |
-
def initialize_client_and_agents(api_key: str):
|
| 51 |
-
try:
|
| 52 |
-
client = Mistral(api_key=api_key)
|
| 53 |
-
doc_agent = create_doc_agent(client)
|
| 54 |
-
image_agent = create_image_agent(client)
|
| 55 |
-
json_analyzer_agent = create_json_analyzer_agent(client)
|
| 56 |
-
speech_agent = create_speech_agent(client)
|
| 57 |
-
return client, {
|
| 58 |
-
"doc_agent_id": doc_agent.id,
|
| 59 |
-
"image_agent_id": image_agent.id,
|
| 60 |
-
"json_analyzer_agent_id": json_analyzer_agent.id,
|
| 61 |
-
"speech_agent_id": speech_agent.id
|
| 62 |
-
}
|
| 63 |
-
except Exception as e:
|
| 64 |
-
return None, f"Error initializing client: {str(e)}"
|
| 65 |
-
|
| 66 |
# Function to handle document processing workflow
|
| 67 |
async def run_document_workflow(api_key: str, file, document_type):
|
| 68 |
if not api_key:
|
|
|
|
| 3 |
import json
|
| 4 |
import os
|
| 5 |
import base64
|
| 6 |
+
from agent import (
|
| 7 |
+
create_doc_agent, create_image_agent, create_json_analyzer_agent,
|
| 8 |
+
create_speech_agent, process_document_workflow, process_image_workflow,
|
| 9 |
+
complete_analysis_workflow, tts_with_mcp, simulate_process_climate_document,
|
| 10 |
+
simulate_analyze_image, simulate_analyze_json_data, simulate_text_to_speech, play_wav
|
| 11 |
+
)
|
| 12 |
from mistralai import Mistral
|
| 13 |
+
|
| 14 |
+
client = None
|
| 15 |
+
agents = None
|
| 16 |
+
|
| 17 |
+
def initialize_client_and_agents(api_key: str):
|
| 18 |
+
global client, agents
|
| 19 |
+
if client is None or agents is None:
|
| 20 |
+
try:
|
| 21 |
+
client = Mistral(api_key=api_key)
|
| 22 |
+
doc_agent = create_doc_agent(client)
|
| 23 |
+
image_agent = create_image_agent(client)
|
| 24 |
+
json_analyzer_agent = create_json_analyzer_agent(client)
|
| 25 |
+
speech_agent = create_speech_agent(client)
|
| 26 |
+
agents = {
|
| 27 |
+
"doc_agent_id": doc_agent.id,
|
| 28 |
+
"image_agent_id": image_agent.id,
|
| 29 |
+
"json_analyzer_agent_id": json_analyzer_agent.id,
|
| 30 |
+
"speech_agent_id": speech_agent.id
|
| 31 |
+
}
|
| 32 |
+
except Exception as e:
|
| 33 |
+
return None, f"Error initializing client: {str(e)}"
|
| 34 |
+
return client, agents
|
| 35 |
|
| 36 |
custom_css = """
|
| 37 |
body {
|
|
|
|
| 68 |
}
|
| 69 |
"""
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
# Function to handle document processing workflow
|
| 72 |
async def run_document_workflow(api_key: str, file, document_type):
|
| 73 |
if not api_key:
|
requirements.txt
CHANGED
|
@@ -4,6 +4,4 @@ pydantic
|
|
| 4 |
IPython
|
| 5 |
gtts
|
| 6 |
gradio
|
| 7 |
-
asyncio
|
| 8 |
-
mcp
|
| 9 |
authlib
|
|
|
|
| 4 |
IPython
|
| 5 |
gtts
|
| 6 |
gradio
|
|
|
|
|
|
|
| 7 |
authlib
|