Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import streamlit as st
|
| 3 |
+
|
| 4 |
+
openai.api_key = st.secrets["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"]
|
| 5 |
+
|
| 6 |
+
# Fine-tuned model name
|
| 7 |
+
MODEL_NAME = "ft:gpt-3.5-turbo-0125:brenin::AjNcIvnw"
|
| 8 |
+
|
| 9 |
+
st.title("Chat with Fine-Tuned GPT-3.5 Turbo")
|
| 10 |
+
st.markdown("This chatbot uses a fine-tuned GPT-3.5 Turbo model.")
|
| 11 |
+
|
| 12 |
+
if "messages" not in st.session_state:
|
| 13 |
+
st.session_state.messages = [
|
| 14 |
+
{"role": "system", "content": "You are a German chatbot. You should help the user by answering their questions."}
|
| 15 |
+
]
|
| 16 |
+
|
| 17 |
+
user_input = st.text_input("Enter your question:")
|
| 18 |
+
|
| 19 |
+
if user_input:
|
| 20 |
+
st.session_state.messages.append({"role": "user", "content": user_input})
|
| 21 |
+
|
| 22 |
+
try:
|
| 23 |
+
response = openai.ChatCompletion.create(
|
| 24 |
+
model=MODEL_NAME,
|
| 25 |
+
messages=st.session_state.messages
|
| 26 |
+
)
|
| 27 |
+
assistant_reply = response.choices[0].message.content
|
| 28 |
+
st.session_state.messages.append({"role": "assistant", "content": assistant_reply})
|
| 29 |
+
except Exception as e:
|
| 30 |
+
assistant_reply = f"Error: {str(e)}"
|
| 31 |
+
|
| 32 |
+
for message in st.session_state.messages:
|
| 33 |
+
if message["role"] == "user":
|
| 34 |
+
st.markdown(f"**User:** {message['content']}")
|
| 35 |
+
elif message["role"] == "assistant":
|
| 36 |
+
st.markdown(f"**Assistant:** {message['content']}")
|