gpt2-deployment / app.py
tchans123's picture
Update
8f0e928
raw
history blame
754 Bytes
import gradio as gr
import openai
import os
# Set your OpenAI API key
openai.api_key = os.getenv("OPENAI_API_KEY") # Make sure to set this environment variable in Hugging Face Spaces
def generate_text(prompt):
response = openai.Completion.create(
engine="text-davinci-003", # You can use other engines like "text-curie-001" or "text-babbage-001"
prompt=prompt,
max_tokens=150,
n=1,
stop=None,
temperature=0.7,
)
return response.choices[0].text.strip()
# Create a Gradio interface
iface = gr.Interface(fn=generate_text, inputs="text", outputs="text", title="GPT-3 Text Generator", description="Enter a prompt to generate text using GPT-3.")
# Launch the interface
iface.launch(public=True)