sidmanale643 commited on
Commit
89facc8
Β·
verified Β·
1 Parent(s): 46f1f7d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -13
app.py CHANGED
@@ -391,13 +391,8 @@ def text_to_speech(text):
391
 
392
  if response.status_code == 200:
393
 
394
- os.makedirs("temp", exist_ok=True)
395
- output_file_path = os.path.join("temp", "output.mp3")
396
- with open(output_file_path, "wb") as f:
397
- f.write(response.content)
398
- print(f"βœ… Audio saved to: {output_file_path}")
399
-
400
- return output_file_path
401
  else:
402
  print(f"❌ Error: {response.status_code} - {response.text}")
403
  return None
@@ -439,7 +434,7 @@ if st.button("Fetch Sentiment Data"):
439
  )
440
 
441
  hindi_translation = translate(final_report , model_provider = "Groq")
442
- audio_path = text_to_speech(hindi_translation)
443
 
444
  output_dict = {
445
  "company_name": company_name,
@@ -447,7 +442,7 @@ if st.button("Fetch Sentiment Data"):
447
  "comparative_sentiment": comparative_sentiment,
448
  "final_report": final_report,
449
  "hindi_translation": hindi_translation,
450
- "audio_url": audio_path,
451
  }
452
 
453
  st.subheader("Company Name")
@@ -456,10 +451,13 @@ if st.button("Fetch Sentiment Data"):
456
  st.subheader("Final Report")
457
  st.write(output_dict.get("final_report"))
458
 
459
- st.subheader("πŸ”Š Audio Output")
460
- if audio_path and os.path.exists(audio_path):
461
- with open(audio_path, "rb") as audio_file:
462
- st.audio(audio_file, format="audio/mp3")
 
 
 
463
 
464
  except requests.exceptions.RequestException as e:
465
  st.error(f"Error fetching data: {e}")
 
391
 
392
  if response.status_code == 200:
393
 
394
+ return response.content
395
+
 
 
 
 
 
396
  else:
397
  print(f"❌ Error: {response.status_code} - {response.text}")
398
  return None
 
434
  )
435
 
436
  hindi_translation = translate(final_report , model_provider = "Groq")
437
+ audio_data = text_to_speech(hindi_translation)
438
 
439
  output_dict = {
440
  "company_name": company_name,
 
442
  "comparative_sentiment": comparative_sentiment,
443
  "final_report": final_report,
444
  "hindi_translation": hindi_translation,
445
+ "audio_text": audio_data,
446
  }
447
 
448
  st.subheader("Company Name")
 
451
  st.subheader("Final Report")
452
  st.write(output_dict.get("final_report"))
453
 
454
+ if st.button("Generate Speech"):
455
+ with st.spinner("Generating audio..."):
456
+ audio_data = output_dict["audio_text"]
457
+
458
+ if audio_data:
459
+ st.audio(audio_data, format="audio/mp3")
460
+
461
 
462
  except requests.exceptions.RequestException as e:
463
  st.error(f"Error fetching data: {e}")