Spaces:
Sleeping
Sleeping
Chatbot
Browse files- app.py +41 -0
- requirements.txt +6 -0
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# from dotenv import load_dotenv
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import openai
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
# Load environment variables
|
| 7 |
+
# load_dotenv()
|
| 8 |
+
|
| 9 |
+
# Set OpenAI API key
|
| 10 |
+
# openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 11 |
+
|
| 12 |
+
# Function to get a response from OpenAI
|
| 13 |
+
def get_openai_response(question):
|
| 14 |
+
try:
|
| 15 |
+
response = openai.ChatCompletion.create(
|
| 16 |
+
model="gpt-3.5-turbo",
|
| 17 |
+
messages=[
|
| 18 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
| 19 |
+
{"role": "user", "content": question}
|
| 20 |
+
],
|
| 21 |
+
temperature=0.5
|
| 22 |
+
)
|
| 23 |
+
return response['choices'][0]['message']['content'].strip()
|
| 24 |
+
except Exception as e:
|
| 25 |
+
return f"An error occurred: {e}"
|
| 26 |
+
|
| 27 |
+
# Initialize Streamlit app
|
| 28 |
+
st.set_page_config(page_title="Q&A Demo")
|
| 29 |
+
|
| 30 |
+
st.header("Langchain Application")
|
| 31 |
+
|
| 32 |
+
input = st.text_input("Input: ", key="input")
|
| 33 |
+
submit = st.button("Ask the question")
|
| 34 |
+
|
| 35 |
+
if submit:
|
| 36 |
+
if input.strip():
|
| 37 |
+
response = get_openai_response(input)
|
| 38 |
+
st.subheader("The Response is")
|
| 39 |
+
st.write(response)
|
| 40 |
+
else:
|
| 41 |
+
st.warning("Please enter a question before submitting.")
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
langchain
|
| 2 |
+
openai
|
| 3 |
+
langchain_community
|
| 4 |
+
huggingface_hub
|
| 5 |
+
python-dotenv
|
| 6 |
+
streamlit
|