File size: 896 Bytes
e46a470
f97bbee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
33
34

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)