thak123 commited on
Commit
a36aeae
1 Parent(s): 87857cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -57
app.py CHANGED
@@ -3,68 +3,16 @@ import classla
3
  classla.download('hr')
4
  nlp = classla.Pipeline('hr')
5
 
6
- # def greet(name):
7
- # doc = nlp(name)
8
- # #print(doc.to_conll())
9
- # return doc.to_conll()
10
-
11
- # iface = gr.Interface(fn=greet, inputs="text", outputs="text")
12
- # iface.launch()
13
-
14
- from gtts import gTTS
15
- import wavio
16
- from io import BytesIO
17
- import base64
18
-
19
- # Function to translate text
20
- def parse_text(text):
21
- doc = nlp(text)
22
  return doc.to_conll()
23
 
24
- # Function to play the original text as audio
25
- def play_original_audio(text_to_play):
26
- tts = gTTS(text_to_play, lang='hr') # Assuming the text is in English
27
- tts.save('original_audio.mp3')
28
-
29
- audio_bytes = BytesIO()
30
- tts.write_to_fp(audio_bytes)
31
- audio_bytes.seek(0)
32
-
33
- audio = base64.b64encode(audio_bytes.read()).decode("utf-8")
34
- audio_player = f'<audio src="data:audio/mpeg;base64,{audio}" controls autoplay></audio>'
35
- return audio_player
36
-
37
-
38
- # Create Gradio interface components
39
- text_input = gr.inputs.Textbox(lines=2, label="Enter text to parse")
40
- parse_button = gr.inputs.Button(text="Parse")
41
- play_audio_button = gr.inputs.Button(text="Play Original Audio")
42
-
43
- # Create a Gradio interface
44
- iface = gr.Interface(
45
- fn=None, # No main function needed
46
- inputs=[text_input, target_language, parse_button, play_audio_button],
47
- outputs=[gr.outputs.Textbox(label="Parsing")],
48
- )
49
-
50
- # Define functions for button clicks
51
- def parse_button_click():
52
- text = text_input.value
53
- target_lang = target_language.value
54
- parsed_text = translate_text(text, target_lang)
55
- iface.outputs[0].update(parsed_text)
56
-
57
- def play_audio_button_click():
58
- text = text_input.value
59
- play_original_audio(text)
60
 
61
- # Assign click functions to buttons
62
- translate_button.command = translate_button_click
63
- play_audio_button.command = play_audio_button_click
64
 
65
 
66
- # Launch the Gradio interface
67
- iface.launch()
68
 
69
 
70
 
 
3
  classla.download('hr')
4
  nlp = classla.Pipeline('hr')
5
 
6
+ def greet(name):
7
+ doc = nlp(name)
8
+ #print(doc.to_conll())
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  return doc.to_conll()
10
 
11
+ iface = gr.Interface(fn=greet, inputs="text", outputs="text")
12
+ iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
 
 
 
14
 
15
 
 
 
16
 
17
 
18