Spaces:
Runtime error
Runtime error
Sync from GitHub via hub-sync
Browse files- app.py +12 -10
- {models → schemas}/__init__.py +0 -0
- schemas/transcription.py +6 -0
app.py
CHANGED
|
@@ -2,11 +2,12 @@ import io
|
|
| 2 |
import numpy as np
|
| 3 |
from scipy.io import wavfile
|
| 4 |
import librosa
|
| 5 |
-
from fastapi import
|
| 6 |
from utils.audio_cleaning import denoise_audio, normalize_audio
|
| 7 |
-
from config.settings import
|
| 8 |
from config import constants
|
| 9 |
from groq import Groq
|
|
|
|
| 10 |
|
| 11 |
groq_client = Groq(api_key=get_settings().groq_secret_key)
|
| 12 |
app = FastAPI()
|
|
@@ -17,8 +18,8 @@ def root():
|
|
| 17 |
return {"status": "ok"}
|
| 18 |
|
| 19 |
|
| 20 |
-
@app.post("/transcribe")
|
| 21 |
-
async def process_and_transcribe(file: UploadFile = File(...)):
|
| 22 |
audio_bytes = await file.read()
|
| 23 |
print(f"File size: {len(audio_bytes)} bytes")
|
| 24 |
if len(audio_bytes) == 0:
|
|
@@ -40,17 +41,18 @@ async def process_and_transcribe(file: UploadFile = File(...)):
|
|
| 40 |
export_buffer.seek(0)
|
| 41 |
|
| 42 |
try:
|
|
|
|
| 43 |
transcription = groq_client.audio.transcriptions.create(
|
| 44 |
-
file=(
|
| 45 |
model=constants.GROQ_MODEL_NAME,
|
| 46 |
response_format="json",
|
| 47 |
language="en",
|
| 48 |
)
|
| 49 |
-
return
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
|
| 55 |
except Exception as e:
|
| 56 |
print(f"Groq API Error: {e}")
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
from scipy.io import wavfile
|
| 4 |
import librosa
|
| 5 |
+
from fastapi import FastAPI, File, UploadFile, HTTPException
|
| 6 |
from utils.audio_cleaning import denoise_audio, normalize_audio
|
| 7 |
+
from config.settings import get_settings
|
| 8 |
from config import constants
|
| 9 |
from groq import Groq
|
| 10 |
+
from schemas.transcription import TranscriptionResponse
|
| 11 |
|
| 12 |
groq_client = Groq(api_key=get_settings().groq_secret_key)
|
| 13 |
app = FastAPI()
|
|
|
|
| 18 |
return {"status": "ok"}
|
| 19 |
|
| 20 |
|
| 21 |
+
@app.post("/transcribe", response_model=TranscriptionResponse)
|
| 22 |
+
async def process_and_transcribe(file: UploadFile = File(...)) -> TranscriptionResponse:
|
| 23 |
audio_bytes = await file.read()
|
| 24 |
print(f"File size: {len(audio_bytes)} bytes")
|
| 25 |
if len(audio_bytes) == 0:
|
|
|
|
| 41 |
export_buffer.seek(0)
|
| 42 |
|
| 43 |
try:
|
| 44 |
+
filename = file.filename if file.filename else "audio.wav"
|
| 45 |
transcription = groq_client.audio.transcriptions.create(
|
| 46 |
+
file=(filename, export_buffer.read()),
|
| 47 |
model=constants.GROQ_MODEL_NAME,
|
| 48 |
response_format="json",
|
| 49 |
language="en",
|
| 50 |
)
|
| 51 |
+
return TranscriptionResponse(
|
| 52 |
+
transcript=transcription.text,
|
| 53 |
+
filename=filename,
|
| 54 |
+
duration_seconds=round(len(waveform) / sr, 2),
|
| 55 |
+
)
|
| 56 |
|
| 57 |
except Exception as e:
|
| 58 |
print(f"Groq API Error: {e}")
|
{models → schemas}/__init__.py
RENAMED
|
File without changes
|
schemas/transcription.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pydantic import BaseModel, Field
|
| 2 |
+
|
| 3 |
+
class TranscriptionResponse(BaseModel):
|
| 4 |
+
transcript: str = Field(..., description="The transcribed text from the audio file")
|
| 5 |
+
filename: str = Field(..., description="The name of the audio file")
|
| 6 |
+
duration_seconds: float = Field(..., description="The duration of the audio file in seconds")
|