File size: 754 Bytes
0c4de91
8f0e928
 
f5cb146
8f0e928
 
f5cb146
8f0e928
 
 
 
 
 
 
 
 
 
f5cb146
31cf435
8f0e928
31cf435
 
8f0e928
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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)