Jammy / app.py
lachie0232's picture
Update app.py
14e8d10 verified
raw
history blame
888 Bytes
import openai
import gradio as gr
# Set up OpenAI API key
openai.api_key = "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"
# Define a function to call the OpenAI API
def chatbot(input_text):
try:
# Updated API call for v1.0.0+
response = openai.Completion.create(
model="gpt-3.5-turbo", # You can change this to GPT-4 or others
prompt=input_text,
max_tokens=150
)
return response['choices'][0]['text'].strip()
except Exception as e:
return f"Error: {str(e)}"
# Create the Gradio interface
iface = gr.Interface(
fn=chatbot,
inputs=gr.Textbox(lines=2, placeholder="Type your message here..."),
outputs=gr.Textbox(),
live=True
)
# Launch the interface
iface.launch()