Spaces:
Sleeping
Sleeping
File size: 658 Bytes
4e5ea86 cd3d012 4e5ea86 cd3d012 |
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 |
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()
|