Spaces:
Runtime error
Runtime error
File size: 908 Bytes
6caa426 |
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 35 36 |
import gradio as gr
import openai
import os
# Read the API key from the .env file
openai.api_key = os.getenv("API_KEY")
# Define the chatbot function
def chatbot(message):
response = openai.Completion.create(
model="gpt-3.5-turbo",
prompt=message,
max_tokens=50,
temperature=0.8,
)
return response.choices[0].text.strip()
# Create the interface
textbox = gr.inputs.Textbox(label="Chat Message")
button = gr.outputs.Button(label="Submit")
output_text = gr.outputs.Textbox(label="Chatbot Response")
def chat_interface(message):
response = chatbot(message)
return response
gr.Interface(
fn=chat_interface,
inputs=textbox,
outputs=output_text,
title="Chat with GPT-3.5 Turbo",
description="This is a chatbot powered by GPT-3.5 Turbo.",
theme="huggingface",
server_port=8080 # Change this to the desired port number
).launch()
|