Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,10 +4,9 @@ import time
|
|
4 |
import streamlit as st
|
5 |
from langchain.llms import openai
|
6 |
|
7 |
-
# Function to get OpenAI response
|
8 |
def get_openai_response(question):
|
9 |
try:
|
10 |
-
api_key = os.environ["OPENAI_API_KEY"]
|
11 |
llm = openai.OpenAI(
|
12 |
model_name="text-davinci-003", temperature=0.5, openai_api_key=api_key
|
13 |
)
|
@@ -18,18 +17,15 @@ def get_openai_response(question):
|
|
18 |
st.error(f"Error: {e}")
|
19 |
return None
|
20 |
|
21 |
-
|
22 |
st.set_page_config(page_title="Enhanced Q&A Demo")
|
23 |
st.header("Langchain App")
|
24 |
|
25 |
-
# User input and submit button
|
26 |
input_text = st.text_input("Ask me anything:", key="input")
|
27 |
submit_button = st.button("Get Answer")
|
28 |
|
29 |
-
# Response history
|
30 |
response_history = st.empty()
|
31 |
|
32 |
-
# Handle button click and display response
|
33 |
if submit_button:
|
34 |
with st.spinner("Processing..."):
|
35 |
response = get_openai_response(input_text)
|
|
|
4 |
import streamlit as st
|
5 |
from langchain.llms import openai
|
6 |
|
|
|
7 |
def get_openai_response(question):
|
8 |
try:
|
9 |
+
api_key = os.environ["OPENAI_API_KEY"]
|
10 |
llm = openai.OpenAI(
|
11 |
model_name="text-davinci-003", temperature=0.5, openai_api_key=api_key
|
12 |
)
|
|
|
17 |
st.error(f"Error: {e}")
|
18 |
return None
|
19 |
|
20 |
+
|
21 |
st.set_page_config(page_title="Enhanced Q&A Demo")
|
22 |
st.header("Langchain App")
|
23 |
|
|
|
24 |
input_text = st.text_input("Ask me anything:", key="input")
|
25 |
submit_button = st.button("Get Answer")
|
26 |
|
|
|
27 |
response_history = st.empty()
|
28 |
|
|
|
29 |
if submit_button:
|
30 |
with st.spinner("Processing..."):
|
31 |
response = get_openai_response(input_text)
|