CananD commited on
Commit
10d4187
·
verified ·
1 Parent(s): 37486da

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from openai import OpenAI
2
+
3
+ client = OpenAI(api_key='OPENAI_API_KEY')
4
+ import streamlit as st
5
+
6
+ # Add your OpenAI API key here
7
+
8
+ # Streamlit title
9
+ st.title("Data Science Instructor Chatbot")
10
+
11
+ # System prompt
12
+ system_prompt = """
13
+ You are a data science instructor. You help students with topics related to data science, machine learning, and artificial intelligence.
14
+ You respond to questions patiently, with clear explanations and a teaching approach.
15
+ """
16
+
17
+ # Session state to store messages
18
+ if 'messages' not in st.session_state:
19
+ st.session_state.messages = []
20
+
21
+ # Display messages
22
+ for message in st.session_state.messages:
23
+ with st.chat_message(message['role']):
24
+ st.markdown(message['content'])
25
+
26
+ # Get user input
27
+ if prompt := st.chat_input("Type your question here..."):
28
+ st.session_state.messages.append({"role": "user", "content": prompt})
29
+ with st.chat_message("user"):
30
+ st.markdown(prompt)
31
+
32
+ # OpenAI API call
33
+ response = client.chat.completions.create(model="gpt-3.5-turbo",
34
+ messages=[
35
+ {"role": "system", "content": system_prompt},
36
+ *st.session_state.messages
37
+ ])
38
+
39
+ # Store and display the response
40
+ response_message = response.choices[0].message.content
41
+ st.session_state.messages.append({"role": "assistant", "content": response_message})
42
+ with st.chat_message("assistant"):
43
+ st.markdown(response_message)