Spaces:
Sleeping
Sleeping
Upload simplechatbot.py
Browse files- simplechatbot.py +30 -0
simplechatbot.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Chatbot
|
| 2 |
+
from langchain_community.llms import OpenAI
|
| 3 |
+
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
load_dotenv() #take environment variable from .env
|
| 6 |
+
|
| 7 |
+
import streamlit as st
|
| 8 |
+
import os
|
| 9 |
+
|
| 10 |
+
## function to load OpenAI model and get reponses
|
| 11 |
+
|
| 12 |
+
def response(question):
|
| 13 |
+
llm = OpenAI(openai_api_key=os.getenv("OPEN_API_KEY"), model_name="gpt-3.5-turbo-instruct",temperature=0.6)
|
| 14 |
+
res= llm(question)
|
| 15 |
+
return res
|
| 16 |
+
# streamlit
|
| 17 |
+
|
| 18 |
+
st.set_page_config(page_title="Question Answering App")
|
| 19 |
+
st.header("Langchain Question Answering App")
|
| 20 |
+
|
| 21 |
+
input = st.text_input("Input: ",key="input")
|
| 22 |
+
res=response(input)
|
| 23 |
+
|
| 24 |
+
submit = st.button("Ask the Question")
|
| 25 |
+
|
| 26 |
+
# when button is clicked, we should get response
|
| 27 |
+
|
| 28 |
+
if submit:
|
| 29 |
+
st.subheader("RESPONSE:")
|
| 30 |
+
st.write(res)
|