-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
52 lines (40 loc) · 1.59 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# app.py
import streamlit as st
from apiCalls import callGPT3
from dotenv import load_dotenv
from maps import get_autocomplete_results, get_map_url, get_place_details, get_street_view_url, image
from print import read_json, display_data
from voice import synthesize_text
load_dotenv()
def main():
input_text = st.text_input("Enter a location", "VNR VJIET")
if input_text:
autocomplete_results = get_autocomplete_results(input_text)
if autocomplete_results['status'] == 'OK':
image(autocomplete_results=autocomplete_results)
st.write("Images render")
else:
st.error("Autocomplete failed. Please try again.")
# Location textbox
user_input = autocomplete_results["predictions"][0]["description"]
st.write(user_input)
if st.button('Submit'):
res = callGPT3(loc=user_input)
print(res)
data = read_json("./response.json")
display_data(data)
# Text-to-Speech
# read the JSON data from the response.json file
data = read_json("./response.json")
history = data.get("History", "No history available.")
ecological = data.get("Ecological Relevance", "No ecological relevance available.")
# Synthesize the text to speech
if st.button("Convert to Speech"):
if history:
with st.spinner("Generating speech..."):
audio_content = synthesize_text(history)
st.audio(audio_content, format="audio/mp3")
else:
st.error("No text to convert to speech.")
if __name__ == "__main__":
main()