Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import time
|
| 3 |
+
from openai import OpenAI
|
| 4 |
+
from mistral_common.audio import Audio
|
| 5 |
+
from mistral_common.protocol.instruct.messages import (
|
| 6 |
+
AudioChunk, TextChunk, UserMessage
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
client = OpenAI(api_key="EMPTY", base_url="http://localhost:8000/v1")
|
| 10 |
+
|
| 11 |
+
def transcribe_and_summarize(audio):
|
| 12 |
+
if not audio:
|
| 13 |
+
return "Please record or upload an audio file."
|
| 14 |
+
|
| 15 |
+
audio_obj = Audio.from_file(audio, strict=False)
|
| 16 |
+
chunk = AudioChunk.from_audio(audio_obj)
|
| 17 |
+
text_chunk = TextChunk(text="Please summarize this audio.")
|
| 18 |
+
user_msg = UserMessage(content=[chunk, text_chunk]).to_openai()
|
| 19 |
+
|
| 20 |
+
response = client.chat.completions.create(
|
| 21 |
+
model="mistralai/Voxtral-Mini-3B-2507",
|
| 22 |
+
messages=[user_msg],
|
| 23 |
+
temperature=0.2,
|
| 24 |
+
top_p=0.95,
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
return response.choices[0].message.content
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
demo = gr.Interface(
|
| 31 |
+
fn=transcribe_and_summarize,
|
| 32 |
+
inputs=gr.Audio(source="microphone", type="filepath", label="Speak now or upload audio"),
|
| 33 |
+
outputs=gr.Textbox(label="Transcription/Summary"),
|
| 34 |
+
title="Voxtral Mini (Mistral) via vLLM",
|
| 35 |
+
description="Transcribe and understand speech using Voxtral Mini 3B with vLLM."
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|