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