Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Q&A Chatbot
|
2 |
+
import os
|
3 |
+
from langchain.llms import OpenAI
|
4 |
+
from dotenv import load_dotenv
|
5 |
+
import streamlit as st
|
6 |
+
|
7 |
+
load_dotenv()
|
8 |
+
|
9 |
+
# Function to load OpenAI model and get responses
|
10 |
+
|
11 |
+
def get_openai_response(question):
|
12 |
+
llm = OpenAI(openai_api_key = os.getenv("OPEN_API_KEY"), model_name = "text-davinci-003", temperature = 0.5)
|
13 |
+
response = llm(question)
|
14 |
+
return response
|
15 |
+
|
16 |
+
# Initialize streamlit app
|
17 |
+
st.set_page_config(page_title= "Q&A Demo")
|
18 |
+
st.header("Langchain Application")
|
19 |
+
|
20 |
+
# Get user input
|
21 |
+
input = st.text_input("Input: ", key= input)
|
22 |
+
response = get_openai_response(input)
|
23 |
+
|
24 |
+
# How we got the input here:
|
25 |
+
|
26 |
+
# 1. Sent the 'input' to the get_openai_response function
|
27 |
+
# 2. OpenAI model was loaded with get_openai_response function, and calls for response using llm
|
28 |
+
# (Instead of llm, we can also use predict message, predict functionality)
|
29 |
+
# (We can also use chain or PromptTemplate instead of LLM)
|
30 |
+
|
31 |
+
submit = st.button("Ask the question")
|
32 |
+
|
33 |
+
# If the above 'ask' button is clicked -
|
34 |
+
if submit: # Means if submit is true
|
35 |
+
st.subheader("The response is ")
|
36 |
+
st.write(response)
|