Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -9,35 +9,26 @@ print("Using GPU for operations when available")
|
|
9 |
|
10 |
# Function to safely load pipeline within a GPU-decorated function
|
11 |
@spaces.GPU
|
12 |
-
def
|
13 |
try:
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
transcription = process_audio_input(audio_input, whisper_processor, whisper_model)
|
20 |
-
elif input_type == "text" and text_input:
|
21 |
-
transcription = text_input
|
22 |
-
else:
|
23 |
-
return "Please provide either audio or text input.", "No input provided.", None
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
# Use the selected language for text-to-speech
|
35 |
-
audio_response = text_to_speech(response, lang_code)
|
36 |
-
|
37 |
-
return transcription, response, audio_response
|
38 |
except Exception as e:
|
39 |
-
|
40 |
-
return
|
|
|
41 |
# Load sarvam-2b for text generation within a GPU-decorated function
|
42 |
@spaces.GPU
|
43 |
def load_sarvam():
|
@@ -250,15 +241,7 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Base().set(
|
|
250 |
gr.Markdown("### Indic Assistant")
|
251 |
|
252 |
input_type = gr.Radio(["audio", "text"], label="Input Type", value="audio")
|
253 |
-
|
254 |
-
with gr.Row():
|
255 |
-
audio_input = gr.Audio(type="filepath", label="Speak (if audio input selected)")
|
256 |
-
language_select = gr.Dropdown(
|
257 |
-
choices=["Bengali", "English", "Gujarati", "Hindi", "Kannada", "Malayalam", "Marathi", "Oriya", "Punjabi", "Tamil", "Telugu"],
|
258 |
-
label="Select Language",
|
259 |
-
value="English"
|
260 |
-
)
|
261 |
-
|
262 |
text_input = gr.Textbox(label="Type your message (if text input selected)")
|
263 |
|
264 |
submit_btn = gr.Button("Submit")
|
@@ -269,7 +252,7 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Base().set(
|
|
269 |
|
270 |
submit_btn.click(
|
271 |
fn=indic_language_assistant,
|
272 |
-
inputs=[input_type, audio_input, text_input
|
273 |
outputs=[output_transcription, output_response, output_audio]
|
274 |
)
|
275 |
gr.HTML("<footer>Powered by Indic Language AI</footer>")
|
|
|
9 |
|
10 |
# Function to safely load pipeline within a GPU-decorated function
|
11 |
@spaces.GPU
|
12 |
+
def load_pipeline(model_name, **kwargs):
|
13 |
try:
|
14 |
+
device = 0 if torch.cuda.is_available() else "cpu"
|
15 |
+
return pipeline(model=model_name, device=device, **kwargs)
|
16 |
+
except Exception as e:
|
17 |
+
print(f"Error loading {model_name} pipeline: {e}")
|
18 |
+
return None
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
+
# Load Whisper model for speech recognition within a GPU-decorated function
|
21 |
+
@spaces.GPU
|
22 |
+
def load_whisper():
|
23 |
+
try:
|
24 |
+
device = 0 if torch.cuda.is_available() else "cpu"
|
25 |
+
processor = WhisperProcessor.from_pretrained("openai/whisper-small")
|
26 |
+
model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-small").to(device)
|
27 |
+
return processor, model
|
|
|
|
|
|
|
|
|
|
|
28 |
except Exception as e:
|
29 |
+
print(f"Error loading Whisper model: {e}")
|
30 |
+
return None, None
|
31 |
+
|
32 |
# Load sarvam-2b for text generation within a GPU-decorated function
|
33 |
@spaces.GPU
|
34 |
def load_sarvam():
|
|
|
241 |
gr.Markdown("### Indic Assistant")
|
242 |
|
243 |
input_type = gr.Radio(["audio", "text"], label="Input Type", value="audio")
|
244 |
+
audio_input = gr.Audio(type="filepath", label="Speak (if audio input selected)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
245 |
text_input = gr.Textbox(label="Type your message (if text input selected)")
|
246 |
|
247 |
submit_btn = gr.Button("Submit")
|
|
|
252 |
|
253 |
submit_btn.click(
|
254 |
fn=indic_language_assistant,
|
255 |
+
inputs=[input_type, audio_input, text_input],
|
256 |
outputs=[output_transcription, output_response, output_audio]
|
257 |
)
|
258 |
gr.HTML("<footer>Powered by Indic Language AI</footer>")
|