Spaces:
Sleeping
Sleeping
vilastadoori
commited on
Commit
•
aca9f12
1
Parent(s):
ea7466b
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import os
|
3 |
+
#from langchain.llms import openai
|
4 |
+
from langchain.llms import OpenAI
|
5 |
+
|
6 |
+
|
7 |
+
from dotenv import load_dotenv
|
8 |
+
|
9 |
+
load_dotenv() #Take environment variables from .env.
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
+
## Function to load OpenAI model and get responses
|
14 |
+
|
15 |
+
def get_openai_response(question):
|
16 |
+
llm=OpenAI(openai_api_key=os.getenv("OPEN_API_KEY"),model_name="gpt-3.5-turbo-instruct",temperature=0.5)
|
17 |
+
response=llm(question)
|
18 |
+
return response
|
19 |
+
|
20 |
+
|
21 |
+
## Initialize our streamlit app
|
22 |
+
|
23 |
+
st.set_page_config(page_title="Q&A Demo")
|
24 |
+
|
25 |
+
st.header("Langchain Application")
|
26 |
+
|
27 |
+
|
28 |
+
input =st.text_input("Input: ", key="input")
|
29 |
+
response = get_openai_response(input)
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
submit = st.button("Ask the Question")
|
34 |
+
|
35 |
+
## if as button is clicked
|
36 |
+
|
37 |
+
if submit:
|
38 |
+
st.subheader("The Response is")
|
39 |
+
st.write(response)
|