Spaces:
Sleeping
Sleeping
Chatbot.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import openai
|
2 |
+
import streamlit as st
|
3 |
+
|
4 |
+
# Initialize the OpenAI API key
|
5 |
+
openai.api_key = 'your-api-key'
|
6 |
+
|
7 |
+
# Function to generate chatbot response
|
8 |
+
def generate_response(user_input):
|
9 |
+
try:
|
10 |
+
response = openai.Completion.create(
|
11 |
+
engine="text-davinci-003", # Use the appropriate GPT-3 engine
|
12 |
+
prompt=user_input,
|
13 |
+
max_tokens=150,
|
14 |
+
temperature=0.7,
|
15 |
+
top_p=1,
|
16 |
+
frequency_penalty=0,
|
17 |
+
presence_penalty=0
|
18 |
+
)
|
19 |
+
return response.choices[0].text.strip()
|
20 |
+
except Exception as e:
|
21 |
+
return f"Error: {str(e)}"
|
22 |
+
|
23 |
+
# Streamlit interface
|
24 |
+
st.title("GPT-3 Chatbot")
|
25 |
+
st.write("Ask me anything!")
|
26 |
+
|
27 |
+
# Text input for user prompt
|
28 |
+
user_input = st.text_input("You: ")
|
29 |
+
|
30 |
+
if user_input:
|
31 |
+
# Generate response when user inputs a question
|
32 |
+
response = generate_response(user_input)
|
33 |
+
st.text_area("Bot:", value=response, height=200)
|