Spaces:
Runtime error
Runtime error
Tidy
Browse files
app.py
CHANGED
@@ -29,8 +29,8 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
29 |
|
30 |
image_description = ""
|
31 |
# audio_output = ""
|
32 |
-
global markdown_output
|
33 |
-
global audio_output
|
34 |
|
35 |
|
36 |
def check_hallucination(assertion, citation):
|
@@ -139,6 +139,7 @@ def process_speech(input_language, audio_input):
|
|
139 |
except Exception as e:
|
140 |
return f"{e}"
|
141 |
|
|
|
142 |
def convert_text_to_speech(input_text: str, source_language: str, target_language: str) -> tuple[str, str]:
|
143 |
client = Client("https://facebook-seamless-m4t.hf.space/--replicas/8cllp/")
|
144 |
|
@@ -153,11 +154,7 @@ def convert_text_to_speech(input_text: str, source_language: str, target_languag
|
|
153 |
target_language,
|
154 |
api_name="/run",
|
155 |
)
|
156 |
-
|
157 |
-
# Check if the result is valid
|
158 |
-
if not result:
|
159 |
-
raise ValueError("No result returned from text-to-speech service")
|
160 |
-
|
161 |
# Initialize variables
|
162 |
translated_text = ""
|
163 |
audio_file_path = ""
|
@@ -176,13 +173,11 @@ def convert_text_to_speech(input_text: str, source_language: str, target_languag
|
|
176 |
audio_file_path = save_audio(item) # Save the audio file
|
177 |
break
|
178 |
|
179 |
-
if not audio_file_path:
|
180 |
-
raise ValueError("No audio file path returned from text-to-speech service")
|
181 |
-
|
182 |
return audio_file_path, translated_text
|
183 |
|
184 |
except Exception as e:
|
185 |
-
return
|
|
|
186 |
|
187 |
def process_image(image_input):
|
188 |
# Initialize the Gradio client with the URL of the Gradio server
|
@@ -515,10 +510,12 @@ languages = {
|
|
515 |
"Vietnamese": "vie"
|
516 |
}
|
517 |
|
|
|
518 |
def clear():
|
519 |
# Return default values for each component
|
520 |
return "English", None, None, "", None
|
521 |
|
|
|
522 |
def create_interface():
|
523 |
# with gr.Blocks(theme='ParityError/Anime') as iface:
|
524 |
with gr.Blocks(theme='ParityError/Anime') as interface:
|
@@ -532,16 +529,16 @@ def create_interface():
|
|
532 |
|
533 |
# Create a dropdown for language selection
|
534 |
input_language = gr.Dropdown(input_language_options, label="Select the language", value="English", interactive=True)
|
535 |
-
|
536 |
with gr.Accordion("Use Voice", open=False) as voice_accordion:
|
537 |
audio_input = gr.Audio(label="Speak")
|
538 |
audio_output = gr.Markdown(label="Output text") # Markdown component for audio
|
539 |
-
gr.Examples([["audio1.wav"],["audio2.wav"],],inputs=[audio_input])
|
540 |
|
541 |
with gr.Accordion("Use a Picture", open=False) as picture_accordion:
|
542 |
image_input = gr.Image(label="Upload image")
|
543 |
image_output = gr.Markdown(label="Output text") # Markdown component for image
|
544 |
-
gr.Examples([["image1.png"], ["image2.jpeg"], ["image3.jpeg"],],inputs=[image_input])
|
545 |
|
546 |
with gr.Accordion("MultiMed", open=False) as multimend_accordion:
|
547 |
text_input = gr.Textbox(label="Use Text", lines=3, placeholder="I have had a sore throat and phlegm for a few days and now my cough has gotten worse!")
|
@@ -555,7 +552,7 @@ def create_interface():
|
|
555 |
["بکل ہرپس کا صحیح علاج کیا ہے؟"],
|
556 |
["구강 헤르페스의 적절한 치료법은 무엇입니까?"],
|
557 |
["Je, ni matibabu gani sahihi kwa herpes ya buccal?"],
|
558 |
-
],inputs=[text_input])
|
559 |
|
560 |
text_output = gr.Markdown(label="MultiMed")
|
561 |
audio_output = gr.Audio(label="Audio Out", type="filepath")
|
@@ -569,5 +566,5 @@ def create_interface():
|
|
569 |
return interface
|
570 |
|
571 |
|
572 |
-
|
573 |
-
|
|
|
29 |
|
30 |
image_description = ""
|
31 |
# audio_output = ""
|
32 |
+
# global markdown_output
|
33 |
+
# global audio_output
|
34 |
|
35 |
|
36 |
def check_hallucination(assertion, citation):
|
|
|
139 |
except Exception as e:
|
140 |
return f"{e}"
|
141 |
|
142 |
+
|
143 |
def convert_text_to_speech(input_text: str, source_language: str, target_language: str) -> tuple[str, str]:
|
144 |
client = Client("https://facebook-seamless-m4t.hf.space/--replicas/8cllp/")
|
145 |
|
|
|
154 |
target_language,
|
155 |
api_name="/run",
|
156 |
)
|
157 |
+
|
|
|
|
|
|
|
|
|
158 |
# Initialize variables
|
159 |
translated_text = ""
|
160 |
audio_file_path = ""
|
|
|
173 |
audio_file_path = save_audio(item) # Save the audio file
|
174 |
break
|
175 |
|
|
|
|
|
|
|
176 |
return audio_file_path, translated_text
|
177 |
|
178 |
except Exception as e:
|
179 |
+
return f"Error in text-to-speech conversion: {str(e)}", ""
|
180 |
+
|
181 |
|
182 |
def process_image(image_input):
|
183 |
# Initialize the Gradio client with the URL of the Gradio server
|
|
|
510 |
"Vietnamese": "vie"
|
511 |
}
|
512 |
|
513 |
+
|
514 |
def clear():
|
515 |
# Return default values for each component
|
516 |
return "English", None, None, "", None
|
517 |
|
518 |
+
|
519 |
def create_interface():
|
520 |
# with gr.Blocks(theme='ParityError/Anime') as iface:
|
521 |
with gr.Blocks(theme='ParityError/Anime') as interface:
|
|
|
529 |
|
530 |
# Create a dropdown for language selection
|
531 |
input_language = gr.Dropdown(input_language_options, label="Select the language", value="English", interactive=True)
|
532 |
+
|
533 |
with gr.Accordion("Use Voice", open=False) as voice_accordion:
|
534 |
audio_input = gr.Audio(label="Speak")
|
535 |
audio_output = gr.Markdown(label="Output text") # Markdown component for audio
|
536 |
+
gr.Examples([["audio1.wav"], ["audio2.wav"], ], inputs=[audio_input])
|
537 |
|
538 |
with gr.Accordion("Use a Picture", open=False) as picture_accordion:
|
539 |
image_input = gr.Image(label="Upload image")
|
540 |
image_output = gr.Markdown(label="Output text") # Markdown component for image
|
541 |
+
gr.Examples([["image1.png"], ["image2.jpeg"], ["image3.jpeg"], ], inputs=[image_input])
|
542 |
|
543 |
with gr.Accordion("MultiMed", open=False) as multimend_accordion:
|
544 |
text_input = gr.Textbox(label="Use Text", lines=3, placeholder="I have had a sore throat and phlegm for a few days and now my cough has gotten worse!")
|
|
|
552 |
["بکل ہرپس کا صحیح علاج کیا ہے؟"],
|
553 |
["구강 헤르페스의 적절한 치료법은 무엇입니까?"],
|
554 |
["Je, ni matibabu gani sahihi kwa herpes ya buccal?"],
|
555 |
+
], inputs=[text_input])
|
556 |
|
557 |
text_output = gr.Markdown(label="MultiMed")
|
558 |
audio_output = gr.Audio(label="Audio Out", type="filepath")
|
|
|
566 |
return interface
|
567 |
|
568 |
|
569 |
+
app = create_interface()
|
570 |
+
app.launch(show_error=True, debug=True)
|