Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Q&A Chatbot
|
2 |
+
from langchain_community.llms.openai import OpenAI
|
3 |
+
from dotenv import load_dotenv
|
4 |
+
import os
|
5 |
+
import streamlit as st
|
6 |
+
|
7 |
+
# Load environment variables from .env.
|
8 |
+
load_dotenv()
|
9 |
+
|
10 |
+
# Function to load OpenAI models and get responses
|
11 |
+
def get_openai_response(question):
|
12 |
+
# Instantiate the OpenAI class with necessary parameters
|
13 |
+
llm = OpenAI(openai_api_key=os.getenv("OPENAI_API_KEY"), model_name="gpt-3.5-turbo-instruct", temperature=0.5)
|
14 |
+
# Use the invoke method to get the response
|
15 |
+
response = llm.invoke(question)
|
16 |
+
return response
|
17 |
+
|
18 |
+
# Initialize our Streamlit app
|
19 |
+
st.set_page_config(page_title='Q&A Demo')
|
20 |
+
st.header("Langchain Application")
|
21 |
+
|
22 |
+
# Streamlit input field
|
23 |
+
input_question = st.text_input("Input: ", key="input")
|
24 |
+
|
25 |
+
# Streamlit button to submit the question
|
26 |
+
submit = st.button("Ask the question")
|
27 |
+
|
28 |
+
# If the "Ask the question" button is clicked
|
29 |
+
if submit and input_question:
|
30 |
+
# Get the response from OpenAI
|
31 |
+
response = get_openai_response(input_question)
|
32 |
+
# Display the response
|
33 |
+
st.subheader("The Response is")
|
34 |
+
st.write(response)
|