rbx-imarcin's picture
Update app.py
cd3d012 verified
raw
history blame
658 Bytes
import gradio as gr
import os
import openai
# Replace 'your_api_key_here' with your actual OpenAI API key
api_token = os.getenv("oaikey")
openai.api_key = api_token
def ask_openai(prompt):
response = openai.ChatCompletion.create(
model="gpt-4", # or any other suitable model
messages=[{"role": "user", "content": prompt}]
)
return response['choices'][0]['message']['content']
# Creating the Gradio Interface
iface = gr.Interface(
fn=ask_openai,
inputs="text",
outputs="text",
title="OpenAI Chatbot",
description="A simple chatbot using OpenAI's GPT model."
)
if __name__ == "__main__":
iface.launch()