legusxyz commited on
Commit
edf3685
·
verified ·
1 Parent(s): 7b23c3d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -26
app.py CHANGED
@@ -1,30 +1,21 @@
1
- import gradio as gr
2
- from transformers import pipeline
3
- import torch
4
- import os
5
- import tempfile
6
- import soundfile as sf
7
 
8
- # Load the Whisper model once during startup
9
- device = 0 if torch.cuda.is_available() else -1
10
- asr_pipeline = pipeline(model="openai/whisper-small", device=device)
11
 
12
- # Function to handle the transcription process
13
- def transcribe_audio(audio_file_path):
14
- # Perform the transcription using the audio file path
15
- transcription = asr_pipeline(audio_file_path)
 
 
16
 
17
- # Return the transcription result
18
- return transcription['text']
 
 
19
 
20
- # Create Gradio interface
21
- interface = gr.Interface(
22
- fn=transcribe_audio, # The function to call when audio is uploaded
23
- inputs=gr.Audio(type="filepath"), # Use 'filepath' to get the path to the audio file
24
- outputs="text", # Output type: text (transcription)
25
- title="Whisper Audio Transcription", # Title of the Gradio interface
26
- description="Upload an audio file to get a transcription using OpenAI's Whisper model"
27
- )
28
-
29
- # Launch the Gradio interface
30
- interface.launch()
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
 
 
 
 
3
 
4
+ app = FastAPI()
 
 
5
 
6
+ # Sample request model
7
+ class Item(BaseModel):
8
+ name: str
9
+ description: str
10
+ price: float
11
+ tax: float
12
 
13
+ # Basic GET endpoint
14
+ @app.get("/")
15
+ def read_root():
16
+ return {"message": "Welcome to the FastAPI app on Hugging Face Spaces!"}
17
 
18
+ # POST endpoint
19
+ @app.post("/items/")
20
+ def create_item(item: Item):
21
+ return {"item": item}