notes73 commited on
Commit
919dd4f
·
0 Parent(s):

Uploaded Interactive Chatbot Assistant project

Browse files
Files changed (2) hide show
  1. app.py +33 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import openai
3
+ import os
4
+
5
+ # Set OpenAI API key
6
+ openai.api_key = os.getenv("OPENAI_API_KEY")
7
+
8
+ if not openai.api_key:
9
+ st.error("⚠️ OpenAI API key is missing! Please add it in Hugging Face secrets.")
10
+ st.stop()
11
+
12
+ # App title
13
+ st.title("🤖 Interactive Chatbot Assistant")
14
+
15
+ # User input
16
+ user_input = st.text_input("You:", "")
17
+
18
+ if st.button("Send"):
19
+ if user_input:
20
+ try:
21
+ response = openai.chat.completions.create(
22
+ model="gpt-4",
23
+ messages=[{"role": "user", "content": user_input}]
24
+ )
25
+ st.text_area("Chatbot:", response.choices[0].message.content, height=200)
26
+ except Exception as e:
27
+ st.error(f"Error: {e}")
28
+ else:
29
+ st.warning("Please enter a message to chat.")
30
+
31
+ st.sidebar.subheader("Chatbot Settings")
32
+ st.sidebar.write("Customize your chatbot experience!")
33
+
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ streamlit
2
+ openai