zaephaer23 commited on
Commit
38fe78d
1 Parent(s): ad61611

Upload chat-app.py

Browse files
Files changed (1) hide show
  1. chat-app.py +32 -0
chat-app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Simple QnA Chatbot
2
+ from langchain.llms import OpenAI
3
+ from dotenv import load_dotenv
4
+ from langchain_google_genai import GoogleGenerativeAI
5
+ import streamlit as st
6
+ import os
7
+
8
+ load_dotenv() # take environment variables from .env.file
9
+
10
+ # Function to load OpenAI and get response
11
+ def get_openai_response(query_prompt):
12
+ #llm = OpenAI(openai_api_key = os.getenv("OPENAI_API_KEY"), model = "gpt-3.5-turbo", temperature=0.9)
13
+ #llm = OpenAI(openai_api_key = os.getenv("OPENAI_API_KEY"), temperature=0.9)
14
+ llmGemini = GoogleGenerativeAI(gemini_api_key=os.environ["GOOGLE_API_KEY"],model="gemini-pro", temperature=0.7)
15
+ #response = llm(query_prompt)
16
+ response = llmGemini(query_prompt)
17
+ return response
18
+
19
+ # Init Streamlit
20
+ st.set_page_config(page_title="QnA Chatbot", page_icon=":robot:", layout="wide")
21
+ st.header("QnA Chatbot using Langchain and OpenAI")
22
+
23
+ # Input area
24
+ input = st.text_area("Ask any question about Langchain and OpenAI.", key="input", height=100)
25
+ response = get_openai_response(input)
26
+
27
+ # When user submits
28
+ submit = st.button("Submit")
29
+ get_openai_response(input)
30
+ if submit:
31
+ st.subheader("Answer: ")
32
+ st.write(response)