Spaces:
Sleeping
Sleeping
import streamlit as st | |
# Initialize the OpenAI API key | |
openai.api_key = 'your-api-key' | |
# Function to generate chatbot response | |
def generate_response(user_input): | |
try: | |
response = openai.Completion.create( | |
engine="text-davinci-003", # Use the appropriate GPT-3 engine | |
prompt=user_input, | |
max_tokens=150, | |
temperature=0.7, | |
top_p=1, | |
frequency_penalty=0, | |
presence_penalty=0 | |
) | |
return response.choices[0].text.strip() | |
except Exception as e: | |
return f"Error: {str(e)}" | |
# Streamlit interface | |
st.title("GPT-3 Chatbot") | |
st.write("Ask me anything!") | |
# Text input for user prompt | |
user_input = st.text_input("You: ") | |
if user_input: | |
# Generate response when user inputs a question | |
response = generate_response(user_input) | |
st.text_area("Bot:", value=response, height=200) | |