Update app.py
Browse files
app.py
CHANGED
@@ -38,48 +38,33 @@ messages = [
|
|
38 |
]
|
39 |
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
flagged = moderator(prompt)
|
53 |
-
st.write('User: ', prompt)
|
54 |
-
if flagged == True:
|
55 |
-
st.warning("Assistant: The latest request violates OpenAI's content policies. Please change it.\n", "π¨")
|
56 |
-
|
57 |
-
else:
|
58 |
-
user_dict = {'role' : 'user', 'content' : prompt}
|
59 |
-
messages.append(user_dict)
|
60 |
-
|
61 |
-
res = client.chat.completions.create(
|
62 |
-
model=gpt_model,
|
63 |
-
messages=messages
|
64 |
)
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
# Streamlit application
|
71 |
-
def combined_model():
|
72 |
-
st.title("Data Science Assistant")
|
73 |
-
curr_question = st.text_area(
|
74 |
-
'enter your prompt',
|
75 |
-
placeholder="Talk to your Data Science Tutor: ",
|
76 |
-
label_visibility="hidden"
|
77 |
-
)
|
78 |
-
if st.button("Generate Answer"):
|
79 |
-
try:
|
80 |
-
chatbot(curr_question)
|
81 |
-
except:
|
82 |
-
st.warning(body="Refresh the page or Try it again later.", icon="π€")
|
83 |
|
|
|
|
|
|
|
84 |
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
]
|
39 |
|
40 |
|
41 |
+
st.title("Data Science Assistant")
|
42 |
+
curr_question = st.text_area(
|
43 |
+
'enter your prompt',
|
44 |
+
placeholder="Talk to your Data Science Tutor: ",
|
45 |
+
label_visibility="hidden"
|
46 |
+
)
|
47 |
+
if st.button("Generate Answer"):
|
48 |
+
try:
|
49 |
+
response = client.moderations.create(
|
50 |
+
input= curr_question,
|
51 |
+
model= moderation_model,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
)
|
53 |
+
flagged = response.results[0].flagged
|
54 |
+
st.write('User: ', curr_question)
|
55 |
+
if flagged == True:
|
56 |
+
st.warning("Assistant: The latest request violates OpenAI's content policies. Please change it.\n", "π¨")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
+
else:
|
59 |
+
user_dict = {'role' : 'user', 'content' : curr_question}
|
60 |
+
messages.append(user_dict)
|
61 |
|
62 |
+
res = client.chat.completions.create(
|
63 |
+
model=gpt_model,
|
64 |
+
messages=messages
|
65 |
+
)
|
66 |
+
assistant_dict = {'role' : res.choices[0].message.role, 'content' : res.choices[0].message.content}
|
67 |
+
messages.append(assistant_dict)
|
68 |
+
st.write("Assistant: ", assistant_dict['content'], "\n")
|
69 |
+
except:
|
70 |
+
st.warning(body="Refresh the page or Try it again later.", icon="π€")
|