Divyansh Kushwaha
commited on
Commit
·
627e458
1
Parent(s):
5b88f13
UPdated
Browse files
api.py
CHANGED
@@ -111,22 +111,10 @@ def get_summary(company_name: str = Query(..., description="Enter company name")
|
|
111 |
def download_json():
|
112 |
return FileResponse(JSON_FILE_PATH, media_type="application/json", filename="final_summary.json")
|
113 |
|
114 |
-
# @app.get("/downloadHindiAudio")
|
115 |
-
# def download_audio():
|
116 |
-
# return FileResponse(AUDIO_FILE_PATH, media_type="audio/mp3", filename="hindi_summary.mp3")
|
117 |
-
|
118 |
@app.get("/downloadHindiAudio")
|
119 |
def download_audio():
|
120 |
-
|
121 |
-
|
122 |
-
def iterfile(): # Generator to read the file in chunks
|
123 |
-
with open(AUDIO_FILE_PATH, mode="rb") as file_like:
|
124 |
-
yield from file_like
|
125 |
-
|
126 |
-
return StreamingResponse(iterfile(), media_type="audio/mp3") # Stream audio as bytes
|
127 |
-
else:
|
128 |
-
print(f"Audio file not found at: {AUDIO_FILE_PATH}")
|
129 |
-
raise HTTPException(status_code=404, detail="Audio file not found.")
|
130 |
|
131 |
if __name__ == "__main__":
|
132 |
import uvicorn
|
|
|
111 |
def download_json():
|
112 |
return FileResponse(JSON_FILE_PATH, media_type="application/json", filename="final_summary.json")
|
113 |
|
|
|
|
|
|
|
|
|
114 |
@app.get("/downloadHindiAudio")
|
115 |
def download_audio():
|
116 |
+
return FileResponse(AUDIO_FILE_PATH, media_type="audio/mp3", filename="hindi_summary.mp3")
|
117 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
if __name__ == "__main__":
|
120 |
import uvicorn
|
app.py
CHANGED
@@ -67,25 +67,10 @@ if st.button("Generate Summary"):
|
|
67 |
st.markdown("#### **Final Sentiment Analysis:**")
|
68 |
st.write(data.get("Final Sentiment Analysis", "No sentiment analysis available."))
|
69 |
|
70 |
-
# Hindi Summary
|
71 |
-
if "play_audio" not in st.session_state:
|
72 |
-
st.session_state["play_audio"] = False
|
73 |
-
|
74 |
-
if st.button("Play Hindi Audio"):
|
75 |
-
st.session_state["play_audio"] = True # Set state to True when button is clicked
|
76 |
-
|
77 |
# Check session state and play audio
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
# Fetch audio data using the API
|
82 |
-
response = requests.get(audio_url, stream=True) # Stream the audio data
|
83 |
-
if response.status_code == 200:
|
84 |
-
st.audio(response.content, format="audio/mp3") # Pass the audio content directly as bytes
|
85 |
-
else:
|
86 |
-
st.error(f"Error: {response.status_code}, {response.text}")
|
87 |
-
except Exception as e:
|
88 |
-
st.error(f"An error occurred while fetching the audio: {e}")
|
89 |
|
90 |
else:
|
91 |
st.error(f"Error: {response.status_code}, {response.text}")
|
|
|
67 |
st.markdown("#### **Final Sentiment Analysis:**")
|
68 |
st.write(data.get("Final Sentiment Analysis", "No sentiment analysis available."))
|
69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
# Check session state and play audio
|
71 |
+
st.markdown("#### **Hindi Summary Audio:**")
|
72 |
+
st.write(data.get("Hindi Summary", "No Hindi summary available."))
|
73 |
+
st.audio(f"{BASE_URL}/downloadHindiAudio", format="audio/mp3")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
else:
|
76 |
st.error(f"Error: {response.status_code}, {response.text}")
|