kahennefer commited on
Commit
053be7e
1 Parent(s): cbeccc1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -9,10 +9,6 @@ from scipy.io.wavfile import write as write_wav
9
  import torch
10
 
11
  def summarize_abstract_from_pdf(pdf_file_path):
12
-
13
-
14
- # Initialize the summarization pipeline
15
-
16
  abstract_string = 'abstract'
17
  found_abstract = False
18
  intro_string ='introduction'
@@ -84,6 +80,21 @@ def generate_audio_func(pdf_file):
84
  return wav_file_path
85
 
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
 
88
  # Define app name, app description, and examples
89
  app_name = "PDF to Audio Converter"
@@ -94,8 +105,8 @@ input_component = gr.File(file_types=["pdf"])
94
  output_component = gr.Audio()
95
 
96
  demo = gr.Interface(
97
- fn=generate_audio_func,
98
- inputs=input_component,
99
  outputs=output_component,
100
  title=app_name,
101
  description=app_description
 
9
  import torch
10
 
11
  def summarize_abstract_from_pdf(pdf_file_path):
 
 
 
 
12
  abstract_string = 'abstract'
13
  found_abstract = False
14
  intro_string ='introduction'
 
80
  return wav_file_path
81
 
82
 
83
+ def generate_audio_func2(text):
84
+
85
+ # Generate audio from text
86
+ #call the summarize abstract function
87
+ audio_array = generate_audio(text)
88
+
89
+ # Create a temporary WAV file to save the audio
90
+ with NamedTemporaryFile(suffix=".wav", delete=False) as temp_wav_file:
91
+ wav_file_path = temp_wav_file.name
92
+ write_wav(wav_file_path, 22050, (audio_array * 32767).astype(np.int16))
93
+ return wav_file_path
94
+
95
+
96
+
97
+
98
 
99
  # Define app name, app description, and examples
100
  app_name = "PDF to Audio Converter"
 
105
  output_component = gr.Audio()
106
 
107
  demo = gr.Interface(
108
+ fn=generate_audio_func2,
109
+ inputs="text",
110
  outputs=output_component,
111
  title=app_name,
112
  description=app_description