Spaces:
Runtime error
Runtime error
File size: 1,692 Bytes
ae4ea47 81136e1 ae4ea47 81136e1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
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()
|