Spaces:
Sleeping
Sleeping
File size: 949 Bytes
eaf8794 11860a4 eaf8794 11860a4 eaf8794 11860a4 eaf8794 11860a4 | 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 31 32 | import streamlit as st
import openai
# Set your OpenAI API key
openai.api_key = 'sk-proj-Jd8bv8afFkjunDur6HD9T3BlbkFJ5s9heeKGsQxC5wMEbgcI'
st.title("Simple Chatbot with Fine-Tuned OpenAI Model")
if 'history' not in st.session_state:
st.session_state.history = []
def generate_response(prompt):
response = openai.Completion.create(
model="fine-tuned-model-id", # Use your fine-tuned model ID
prompt=prompt,
max_tokens=150
)
return response.choices[0].text.strip()
user_input = st.text_input("You:", key='input')
if user_input:
st.session_state.history.append({"role": "user", "content": user_input})
response = generate_response(user_input)
st.session_state.history.append({"role": "bot", "content": response})
for message in st.session_state.history:
if message['role'] == 'user':
st.write(f"You: {message['content']}")
else:
st.write(f"Bot: {message['content']}")
|