MK-316 commited on
Commit
ca2120d
1 Parent(s): c723aa5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -5
app.py CHANGED
@@ -7,20 +7,31 @@ import os
7
  import nltk
8
  nltk.download('punkt')
9
 
10
- # Global variable to store sentences
11
  sentences = []
 
12
 
13
  # Function to process text and generate sentence options
14
  def process_text(mytext):
15
- global sentences
 
16
  sentences = tokenize.sent_tokenize(mytext)
17
- return [f"{i + 1}. {s}" for i, s in enumerate(sentences)]
 
18
 
19
- # Function to generate audio for the selected sentence
20
  def generate_audio(selected_item):
 
 
21
  if not selected_item:
22
  return None
23
 
 
 
 
 
 
 
24
  index = int(selected_item.split('.')[0]) - 1 # Adjust for 0-based index
25
 
26
  if 0 <= index < len(sentences):
@@ -51,4 +62,4 @@ with gr.Blocks() as app:
51
  submit_button.click(fn=update_dropdown, inputs=textbox, outputs=dropdown)
52
  dropdown.change(fn=generate_audio, inputs=dropdown, outputs=audio_output)
53
 
54
- app.launch()
 
7
  import nltk
8
  nltk.download('punkt')
9
 
10
+ # Global variable to store sentences and the entire text
11
  sentences = []
12
+ full_text = ""
13
 
14
  # Function to process text and generate sentence options
15
  def process_text(mytext):
16
+ global sentences, full_text
17
+ full_text = mytext
18
  sentences = tokenize.sent_tokenize(mytext)
19
+ choices = ["Play the whole text"] + [f"{i + 1}. {s}" for i, s in enumerate(sentences)]
20
+ return choices
21
 
22
+ # Function to generate audio for the selected item
23
  def generate_audio(selected_item):
24
+ global full_text
25
+
26
  if not selected_item:
27
  return None
28
 
29
+ if selected_item == "Play the whole text":
30
+ tts = gTTS(text=full_text, lang='en')
31
+ audio_path = 'full_text.mp3'
32
+ tts.save(audio_path)
33
+ return audio_path
34
+
35
  index = int(selected_item.split('.')[0]) - 1 # Adjust for 0-based index
36
 
37
  if 0 <= index < len(sentences):
 
62
  submit_button.click(fn=update_dropdown, inputs=textbox, outputs=dropdown)
63
  dropdown.change(fn=generate_audio, inputs=dropdown, outputs=audio_output)
64
 
65
+ app.launch(share=True)