Spaces:
Sleeping
Sleeping
Update app.py
#1
by
hkccwong
- opened
app.py
CHANGED
|
@@ -1,48 +1,30 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
st.
|
| 31 |
-
st.write("Ask your question and get a response from the AI.")
|
| 32 |
-
|
| 33 |
-
user_input = st.text_input("Your question:")
|
| 34 |
-
if st.button("Send"):
|
| 35 |
-
if user_input:
|
| 36 |
-
response = openai.ChatCompletion.create(
|
| 37 |
-
engine="gpt-35-turbo",
|
| 38 |
-
messages=[{"role": "system", "content": "You are an AI assistant that helps people find information."},
|
| 39 |
-
{"role": "user", "content": user_input}],
|
| 40 |
-
max_tokens=800,
|
| 41 |
-
top_p=0.95,
|
| 42 |
-
frequency_penalty=0,
|
| 43 |
-
presence_penalty=0,
|
| 44 |
-
stop=None)
|
| 45 |
-
|
| 46 |
-
st.write("AI response:", response.choices[0].message["content"])
|
| 47 |
-
else:
|
| 48 |
-
st.write("Please enter a question.")
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import openai
|
| 3 |
+
import streamlit as st
|
| 4 |
+
|
| 5 |
+
# Set up OpenAI API
|
| 6 |
+
openai.api_type = "azure"
|
| 7 |
+
openai.api_base = "https://fevaworksopenai.openai.azure.com/"
|
| 8 |
+
openai.api_version = "2023-03-15-preview"
|
| 9 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 10 |
+
|
| 11 |
+
# Streamlit app
|
| 12 |
+
st.title("AI Chatbot")
|
| 13 |
+
st.write("Ask your question and get a response from the AI.")
|
| 14 |
+
|
| 15 |
+
user_input = st.text_input("Your question:")
|
| 16 |
+
if st.button("Send"):
|
| 17 |
+
if user_input:
|
| 18 |
+
response = openai.ChatCompletion.create(
|
| 19 |
+
engine="gpt-35-turbo",
|
| 20 |
+
messages=[{"role": "system", "content": "You are an AI assistant that helps people find information."},
|
| 21 |
+
{"role": "user", "content": user_input}],
|
| 22 |
+
max_tokens=800,
|
| 23 |
+
top_p=0.95,
|
| 24 |
+
frequency_penalty=0,
|
| 25 |
+
presence_penalty=0,
|
| 26 |
+
stop=None)
|
| 27 |
+
|
| 28 |
+
st.text_area("AI response:", value=response.choices[0].text)
|
| 29 |
+
else:
|
| 30 |
+
st.write("Please enter a question.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|