File size: 780 Bytes
7d7a869
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fc66424
7d7a869
 
 
fc66424
7d7a869
 
 
 
 
 
 
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
28
29
30
31
32
33
import gradio as gr
import openai

# Authenticate with OpenAI API
openai.api_key = "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"

# Define GPT-2 model
model_engine = "text-davinci-002"
prompt = "Write a short paragraph about a topic of your choice:"

def generate_text(prompt):
    # Use GPT-2 to generate text based on user input
    response = openai.Completion.create(
        engine=model_engine,
        prompt=prompt,
        max_tokens=1024,
        n=1,
        stop=None,
        temperature=0.5,
    )
    return response.choices[0].text

# Create Gradio interface
interface = gr.Interface(
    generate_text,
    inputs=gr.inputs.Textbox(prompt),
    outputs=gr.outputs.Textbox(),
    title="GPT-2 Text Generation",
)

# Launch the interface
interface.launch()