Spaces:
Runtime error
Runtime error
import gradio as gr | |
import classla | |
classla.download('hr') | |
nlp = classla.Pipeline('hr') | |
# def greet(name): | |
# doc = nlp(name) | |
# #print(doc.to_conll()) | |
# return doc.to_conll() | |
# iface = gr.Interface(fn=greet, inputs="text", outputs="text") | |
# iface.launch() | |
import gradio as gr | |
from gtts import gTTS | |
import pygame | |
# Initialize the pygame mixer | |
pygame.mixer.init() | |
# Function to translate text | |
def parse_text(text): | |
doc = nlp(text) | |
return doc.to_conll() | |
# Function to play the original text as audio | |
def play_original_audio(text_to_play): | |
tts = gTTS(text_to_play, lang='hr') # Assuming the text is in English | |
tts.save('original_audio.mp3') | |
pygame.mixer.music.load('original_audio.mp3') | |
pygame.mixer.music.play() | |
# Create Gradio interface components | |
text_input = gr.inputs.Textbox(lines=2, label="Enter text to parse") | |
parse_button = gr.inputs.Button(text="Parse") | |
play_audio_button = gr.inputs.Button(text="Play Original Audio") | |
# Create a Gradio interface | |
iface = gr.Interface( | |
fn=None, # No main function needed | |
inputs=[text_input, target_language, parse_button, play_audio_button], | |
outputs=[gr.outputs.Textbox(label="Parsing")], | |
) | |
# Define functions for button clicks | |
def parse_button_click(): | |
text = text_input.value | |
target_lang = target_language.value | |
parsed_text = translate_text(text, target_lang) | |
iface.outputs[0].update(parsed_text) | |
def play_audio_button_click(): | |
text = text_input.value | |
play_original_audio(text) | |
# Assign click functions to buttons | |
translate_button.command = translate_button_click | |
play_audio_button.command = play_audio_button_click | |
# Launch the Gradio interface | |
iface.launch() | |