Parthi07 commited on
Commit
cd9da6c
·
verified ·
1 Parent(s): 2807727

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +43 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Q&A Chatbot
2
+
3
+ import openai
4
+ from dotenv import load_dotenv
5
+ import streamlit as st
6
+ import os
7
+
8
+ # Load the enviroment variables from .env file
9
+ load_dotenv()
10
+
11
+ # Set the API key from environment variable
12
+ openai.api_key = os.getenv("OPENAI_API_KEY")
13
+
14
+ # Function to load OpenAI model to get response
15
+
16
+ def get_openai_response(prompt):
17
+ response = openai.ChatCompletion.create(
18
+ model="gpt-3.5-turbo", # You can change this to gpt-4 if you prefer
19
+ messages=[
20
+ {"role": "system", "content": "You are a helpful assistant."},
21
+ {"role": "user", "content": prompt}
22
+ ]
23
+ )
24
+ # Return the assistant's reply
25
+ return response['choices'][0]['message']['content']
26
+
27
+ # Initialize streamlit page
28
+ st.set_page_config(page_title="Q&A Chatbot")
29
+
30
+ st.header("Langchain Application")
31
+
32
+ input= st.text_input("Enter your prompt:")
33
+ submit=st.button("Submit")
34
+
35
+ # If button is clicked, get and display the response
36
+
37
+ if submit:
38
+ response = get_openai_response(input)
39
+ st.subheader("Response")
40
+ st.write(response)
41
+
42
+
43
+
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ langchain
2
+ openai
3
+ huggingface_hub
4
+ python-dotenv
5
+ streamlit