Agent Test
Browse files- Dockerfile +33 -0
- README.md +14 -0
- main.py +54 -0
- requirements.text +5 -0
Dockerfile
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.9-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
# Install system dependencies
|
| 6 |
+
RUN apt-get update && apt-get install -y \
|
| 7 |
+
build-essential \
|
| 8 |
+
curl \
|
| 9 |
+
git \
|
| 10 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
+
|
| 12 |
+
# Set environment variables for FastAPI, transformers, etc.
|
| 13 |
+
ENV HOME=/app
|
| 14 |
+
ENV XDG_CONFIG_HOME=/app/.config
|
| 15 |
+
ENV XDG_CACHE_HOME=/app/.cache
|
| 16 |
+
|
| 17 |
+
# Create config/cache directories
|
| 18 |
+
RUN mkdir -p /app/.config /app/.cache
|
| 19 |
+
|
| 20 |
+
# Copy requirements first for caching and install dependencies
|
| 21 |
+
COPY requirements.txt ./
|
| 22 |
+
|
| 23 |
+
# Install Python dependencies, including watsonx orchestrate
|
| 24 |
+
RUN pip install --upgrade pip && \
|
| 25 |
+
pip install --upgrade ibm-watsonx-orchestrate && \
|
| 26 |
+
pip install -r requirements.txt
|
| 27 |
+
|
| 28 |
+
# Copy the rest of your app
|
| 29 |
+
COPY . .
|
| 30 |
+
|
| 31 |
+
EXPOSE 7860
|
| 32 |
+
|
| 33 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
README.md
CHANGED
|
@@ -10,3 +10,17 @@ short_description: AI powered Meeting Memory Workflow and Automation
|
|
| 10 |
---
|
| 11 |
|
| 12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 13 |
+
|
| 14 |
+
/
|
| 15 |
+
βββ main.py # FastAPI application entry point
|
| 16 |
+
βββ requirements.txt # Python dependencies
|
| 17 |
+
βββ static/ # Static files (JS, CSS, images)
|
| 18 |
+
β βββ style.css
|
| 19 |
+
β βββ script.js
|
| 20 |
+
βββ templates/ # HTML templates for Jinja2 (for FastAPI responses)
|
| 21 |
+
β βββ index.html
|
| 22 |
+
βββ agents/ # (Optional) Python modules for each agent
|
| 23 |
+
β βββ transcription_agent.py
|
| 24 |
+
β βββ summarizer_agent.py
|
| 25 |
+
β βββ orchestrate_agent.py
|
| 26 |
+
βββ README.md
|
main.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, File, UploadFile, Form
|
| 2 |
+
from fastapi.responses import HTMLResponse, JSONResponse
|
| 3 |
+
import torch
|
| 4 |
+
import torchaudio
|
| 5 |
+
from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq, AutoTokenizer, AutoModelForCausalLM
|
| 6 |
+
|
| 7 |
+
app = FastAPI()
|
| 8 |
+
|
| 9 |
+
# Load IBM Granite models once on startup
|
| 10 |
+
SPEECH_MODEL = "ibm-granite/granite-speech-3.3-8b"
|
| 11 |
+
LLM_MODEL = "ibm-granite/granite-3.3-8b-instruct"
|
| 12 |
+
|
| 13 |
+
speech_processor = AutoProcessor.from_pretrained(SPEECH_MODEL)
|
| 14 |
+
speech_model = AutoModelForSpeechSeq2Seq.from_pretrained(SPEECH_MODEL).to("cpu")
|
| 15 |
+
tokenizer = AutoTokenizer.from_pretrained(LLM_MODEL)
|
| 16 |
+
llm_model = AutoModelForCausalLM.from_pretrained(LLM_MODEL).to("cpu")
|
| 17 |
+
|
| 18 |
+
@app.get("/", response_class=HTMLResponse)
|
| 19 |
+
def home():
|
| 20 |
+
return """
|
| 21 |
+
<h1>Meeting Memory Workflow Automation</h1>
|
| 22 |
+
<form action="/transcribe" enctype="multipart/form-data" method="post">
|
| 23 |
+
<input type="file" name="audiofile" accept="audio/*" required/>
|
| 24 |
+
<button type="submit">Upload & Transcribe</button>
|
| 25 |
+
</form>
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
@app.post("/transcribe")
|
| 29 |
+
async def transcribe(audiofile: UploadFile = File(...)):
|
| 30 |
+
audio_bytes = await audiofile.read()
|
| 31 |
+
import io
|
| 32 |
+
wav = io.BytesIO(audio_bytes)
|
| 33 |
+
audio, sample_rate = torchaudio.load(wav)
|
| 34 |
+
|
| 35 |
+
inputs = speech_processor(audio, sampling_rate=sample_rate, return_tensors="pt").to(speech_model.device)
|
| 36 |
+
generated_ids = speech_model.generate(**inputs)
|
| 37 |
+
transcript = speech_processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 38 |
+
|
| 39 |
+
# Summarize
|
| 40 |
+
prompt = f"Summarize the following text: {transcript}"
|
| 41 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(llm_model.device)
|
| 42 |
+
summary_ids = llm_model.generate(**inputs, max_new_tokens=200)
|
| 43 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True).replace(prompt, "").strip()
|
| 44 |
+
|
| 45 |
+
html = f"""
|
| 46 |
+
<h2>Transcript</h2>
|
| 47 |
+
<pre>{transcript}</pre>
|
| 48 |
+
<h2>Summary</h2>
|
| 49 |
+
<pre>{summary}</pre>
|
| 50 |
+
<a href="/">Back</a>
|
| 51 |
+
"""
|
| 52 |
+
return HTMLResponse(content=html)
|
| 53 |
+
|
| 54 |
+
# Add any orchestration/agent endpoints as needed!
|
requirements.text
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn
|
| 3 |
+
transformers
|
| 4 |
+
torch
|
| 5 |
+
torchaudio
|