dummydj2633 commited on
Commit
bd29083
·
verified ·
1 Parent(s): cae409f

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +30 -0
main.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import openai
3
+
4
+ def main():
5
+ st.title("AI Chatbot")
6
+
7
+ # Input field for OpenAI API Key
8
+ api_key = st.text_input("Enter your OpenAI API Key", type="password")
9
+
10
+ if api_key:
11
+ openai.api_key = api_key
12
+
13
+ user_input = st.text_area("Ask me anything:")
14
+
15
+ if st.button("Generate Response"):
16
+ if user_input.strip() != "":
17
+ response = openai.ChatCompletion.create(
18
+ model="gpt-3.5-turbo",
19
+ messages=[{"role": "user", "content": user_input}]
20
+ )
21
+
22
+ st.subheader("Response:")
23
+ st.write(response["choices"][0]["message"]["content"])
24
+ else:
25
+ st.warning("Please enter a question.")
26
+ else:
27
+ st.warning("Please enter your OpenAI API Key to proceed.")
28
+
29
+ if __name__ == "__main__":
30
+ main()