capradeepgujaran commited on
Commit
3f1f36e
1 Parent(s): d9cfca5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -57
app.py CHANGED
@@ -245,60 +245,4 @@ if __name__ == "__main__":
245
  demo = create_gradio_interface()
246
  demo.launch()
247
  else:
248
- demo = create_gradio_interface()/////////////////////////////////////openai_tts_tool.py// from openai import OpenAI
249
- import tempfile
250
- import os
251
-
252
- def generate_audio_and_text(api_key, input_text, model_name, voice_type, voice_speed, language, output_option, summary_length, additional_prompt):
253
- if not input_text:
254
- return None, "No input text provided"
255
-
256
- try:
257
- client = OpenAI(api_key=api_key)
258
-
259
- # Generate summary if requested
260
- summary_text = None
261
- if output_option in ["summary_text", "both"]:
262
- summary_prompt = f"Summarize the following text in approximately {summary_length} words. {additional_prompt or ''}\n\nText: {input_text}"
263
-
264
- summary_response = client.chat.completions.create(
265
- model=model_name,
266
- messages=[{"role": "user", "content": summary_prompt}]
267
- )
268
- summary_text = summary_response.choices[0].message.content
269
-
270
- # Generate audio if requested
271
- audio_file = None
272
- if output_option in ["audio", "both"]:
273
- speech_response = client.audio.speech.create(
274
- model="tts-1", # or "tts-1-hd" for higher quality
275
- voice=voice_type,
276
- input=input_text,
277
- speed=float(voice_speed)
278
- )
279
-
280
- # Create temp directory if it doesn't exist
281
- temp_dir = os.path.join(os.getcwd(), 'temp')
282
- if not os.path.exists(temp_dir):
283
- os.makedirs(temp_dir)
284
-
285
- # Save the audio to a temporary file
286
- audio_path = os.path.join(temp_dir, f"output_{hash(input_text)}.mp3")
287
- with open(audio_path, "wb") as f:
288
- for chunk in speech_response.iter_bytes():
289
- f.write(chunk)
290
-
291
- audio_file = audio_path
292
-
293
- # Return based on output option
294
- if output_option == "summary_text":
295
- return None, summary_text
296
- elif output_option == "audio":
297
- return audio_file, None
298
- elif output_option == "both":
299
- return audio_file, summary_text
300
-
301
- except Exception as e:
302
- return None, f"Error: {str(e)}"
303
-
304
- return None, None
 
245
  demo = create_gradio_interface()
246
  demo.launch()
247
  else:
248
+ demo = create_gradio_interface()