-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathui.py
52 lines (46 loc) · 1.69 KB
/
ui.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
#for ui and accepting user input as audio , play output audio file
import streamlit as st
from streamlit_mic_recorder import speech_to_text
#parsing and extracting cituy
from langchain_openai import ChatOpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
import os
from langchain_community.utilities import OpenWeatherMapAPIWrapper
import json
from audio_gen import generate_audio
os.environ["OPENWEATHERMAP_API_KEY"] = "90cd0252d44c2c0223aa6bff746d9626"
weather = OpenWeatherMapAPIWrapper()
llm=ChatOpenAI(model="gpt-4o")
prompt="""
you are an intelligent assistant who is very good in world geography , your main task is to extract the city name from a sentence{instruction}
and return output as json , while returning the json use the below key :
city
please note you have to only return the json nothing else
"""
def genresponse(input):
query_with_prompt=PromptTemplate(
template=prompt,
input_variables=["instruction"]
)
llmchain=LLMChain(llm=llm,prompt=query_with_prompt,verbose=True)
response=llmchain.invoke(
{"instruction":input}
)
data=response["text"]
data=data.replace("json","")
data=data.replace("`","")
data=json.loads(data)
return data
llm=ChatOpenAI(model="gpt-4o")
st.title("VOICE ENABLED NEWS APP")
st.write("ask anything")
text=speech_to_text(language="en",use_container_width=True,just_once=True,key="STT")
if text is not None:
data=genresponse(text)
city_name=data["city"]
st.write(city_name)
weather_data = weather.run(city_name)
st.write(weather_data)
generate_audio(weather_data)
st.audio(data="output.wav",format="audio/wav",autoplay=True)