Spaces:
Runtime error
Runtime error
import os | |
import gradio as gr | |
# Import the OpenAI Python library | |
from openai import OpenAI | |
# Load your API key from an environment variable or secret management service | |
%set_env OPENAI_API_KEY="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" | |
# Define a function that uses the OpenAI Completion API to generate text | |
def chatgpt(prompt, examples=[]): | |
response = openai.Completion.create( | |
engine="text-davinci-003", | |
prompt=prompt + "\n\nExamples:\n" + "\n".join(examples), | |
temperature=0.5, | |
max_tokens=100, | |
top_p=1, | |
frequency_penalty=0, | |
presence_penalty=0, | |
stop=["\n"] | |
) | |
return response.choices[0].text | |
# Define the Gradio interface | |
# Define the Gradio interface | |
interface = gr.Interface( | |
fn=chatgpt, | |
inputs=[ | |
gr.Textbox( | |
show_label=False, | |
placeholder="Enter your prompt here..." | |
), | |
gr.Textbox( | |
show_label=False, | |
placeholder="Enter some examples, separated by newlines..." | |
) | |
], | |
outputs="text", | |
title="Convera", | |
description="A conversational AI powered by OpenAI and Gradio." | |
) | |
# Launch the interface | |
interface.launch(share=True) |