Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,25 +9,28 @@ 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 |
-
print(f"Error loading {model_name} pipeline: {e}")
|
18 |
-
return None
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
28 |
except Exception as e:
|
29 |
-
|
30 |
-
return
|
31 |
|
32 |
# Load sarvam-2b for text generation within a GPU-decorated function
|
33 |
@spaces.GPU
|
@@ -241,7 +244,15 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Base().set(
|
|
241 |
gr.Markdown("### Indic Assistant")
|
242 |
|
243 |
input_type = gr.Radio(["audio", "text"], label="Input Type", value="audio")
|
244 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
245 |
text_input = gr.Textbox(label="Type your message (if text input selected)")
|
246 |
|
247 |
submit_btn = gr.Button("Submit")
|
@@ -252,7 +263,7 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Base().set(
|
|
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>")
|
|
|
9 |
|
10 |
# Function to safely load pipeline within a GPU-decorated function
|
11 |
@spaces.GPU
|
12 |
+
def indic_language_assistant(input_type, audio_input, text_input, selected_language):
|
13 |
try:
|
14 |
+
# Load models within the GPU-decorated function
|
15 |
+
whisper_processor, whisper_model = load_whisper()
|
16 |
+
sarvam_pipe = load_sarvam()
|
|
|
|
|
17 |
|
18 |
+
if input_type == "audio" and audio_input is not None:
|
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 |
+
response = generate_response(transcription, sarvam_pipe)
|
26 |
+
|
27 |
+
# Use the selected language for text-to-speech
|
28 |
+
audio_response = text_to_speech(response, selected_language)
|
29 |
+
|
30 |
+
return transcription, response, audio_response
|
31 |
except Exception as e:
|
32 |
+
error_message = f"An error occurred: {str(e)}"
|
33 |
+
return error_message, error_message, None
|
34 |
|
35 |
# Load sarvam-2b for text generation within a GPU-decorated function
|
36 |
@spaces.GPU
|
|
|
244 |
gr.Markdown("### Indic Assistant")
|
245 |
|
246 |
input_type = gr.Radio(["audio", "text"], label="Input Type", value="audio")
|
247 |
+
|
248 |
+
with gr.Row():
|
249 |
+
audio_input = gr.Audio(type="filepath", label="Speak (if audio input selected)")
|
250 |
+
language_select = gr.Dropdown(
|
251 |
+
choices=["Bengali", "English", "Gujarati", "Hindi", "Kannada", "Malayalam", "Marathi", "Oriya", "Punjabi", "Tamil", "Telugu"],
|
252 |
+
label="Select Language",
|
253 |
+
value="English"
|
254 |
+
)
|
255 |
+
|
256 |
text_input = gr.Textbox(label="Type your message (if text input selected)")
|
257 |
|
258 |
submit_btn = gr.Button("Submit")
|
|
|
263 |
|
264 |
submit_btn.click(
|
265 |
fn=indic_language_assistant,
|
266 |
+
inputs=[input_type, audio_input, text_input, language_select],
|
267 |
outputs=[output_transcription, output_response, output_audio]
|
268 |
)
|
269 |
gr.HTML("<footer>Powered by Indic Language AI</footer>")
|