Spaces:
Sleeping
Sleeping
atifali-pm
commited on
Commit
•
7021825
1
Parent(s):
2793365
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from langchain.llms import OpenAI
|
2 |
+
from dotenv import load_dotenv
|
3 |
+
import os
|
4 |
+
|
5 |
+
load_dotenv()
|
6 |
+
|
7 |
+
|
8 |
+
import streamlit as st
|
9 |
+
|
10 |
+
## function to load openai and get responses
|
11 |
+
|
12 |
+
def get_openai_response(quesetion):
|
13 |
+
llm=OpenAI(openai_api_key=os.getenv("OPEN_API_KEY"), model_name="text-davinci-003", temperature=0.5)
|
14 |
+
response = llm(quesetion)
|
15 |
+
return response
|
16 |
+
|
17 |
+
## initialize streamlit and set input field and button
|
18 |
+
st.set_page_config(page_title="Q&A demo")
|
19 |
+
st.header("Langchain application")
|
20 |
+
|
21 |
+
input = st.text_input("Input: ", key="input")
|
22 |
+
response = get_openai_response(input)
|
23 |
+
|
24 |
+
submit = st.button("Ask the question")
|
25 |
+
|
26 |
+
|
27 |
+
## if button is submitted
|
28 |
+
if submit:
|
29 |
+
st.subheader("The response is")
|
30 |
+
st.write(response)
|