Upload 2 files
Browse files- app.py +44 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from openai import OpenAI
|
| 2 |
+
from mistral_common.audio import Audio
|
| 3 |
+
from mistral_common.protocol.instruct.messages import AudioChunk, TextChunk, UserMessage
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import httpx
|
| 6 |
+
|
| 7 |
+
# Patch transport to remove auth headers
|
| 8 |
+
class NoAuth(httpx.Auth):
|
| 9 |
+
def auth_flow(self, request):
|
| 10 |
+
yield request
|
| 11 |
+
|
| 12 |
+
client = OpenAI(
|
| 13 |
+
base_url="https://Koaris-voxserve.hf.space/v1",
|
| 14 |
+
http_client=httpx.Client(auth=NoAuth())
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
model = "mistralai/Voxtral-Mini-3B-2507" # or just hardcode it
|
| 18 |
+
|
| 19 |
+
def transcribe(audio_file):
|
| 20 |
+
if not audio_file:
|
| 21 |
+
return "Please record something."
|
| 22 |
+
|
| 23 |
+
with open(audio_file, "rb") as f:
|
| 24 |
+
audio_bytes = f.read()
|
| 25 |
+
|
| 26 |
+
audio = Audio.from_bytes(audio_bytes, strict=False)
|
| 27 |
+
chunk = AudioChunk.from_audio(audio)
|
| 28 |
+
prompt = TextChunk(text="Please transcribe this audio.")
|
| 29 |
+
user_msg = UserMessage(content=[chunk, prompt]).to_openai()
|
| 30 |
+
|
| 31 |
+
response = client.chat.completions.create(
|
| 32 |
+
model=model,
|
| 33 |
+
messages=[user_msg],
|
| 34 |
+
temperature=0.0
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
return response.choices[0].message.content
|
| 38 |
+
|
| 39 |
+
gr.Interface(
|
| 40 |
+
fn=transcribe,
|
| 41 |
+
inputs=gr.Audio(type="filepath", label="Record your voice"),
|
| 42 |
+
outputs=gr.Textbox(label="Transcription"),
|
| 43 |
+
title="Transcribe Audio with Voxtral",
|
| 44 |
+
).launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
openai
|
| 3 |
+
mistral_common[audio]
|
| 4 |
+
huggingface_hub
|