File size: 1,792 Bytes
da277b2
8d84951
a93f39d
8a4cad7
8d84951
da277b2
a8450e3
8a4cad7
5c8a925
6da864d
a8450e3
d03708d
6168bbf
8d84951
a8450e3
 
c38fbf1
d03708d
 
e318446
8d84951
 
38b0ecd
a8450e3
2a47e9a
8d84951
 
 
 
 
 
539fc5d
 
8a4cad7
3b21992
 
a93f39d
 
3b21992
 
 
 
 
 
 
 
 
 
7d52c76
a93f39d
 
 
 
 
 
 
7d52c76
a93f39d
3b21992
 
a93f39d
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import openai
import gradio as gr
from gradio.components import Textbox, Image, Text

# Set up OpenAI API credentials
openai.api_key = "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"

model_path = "models/dreamlike-art/dreamlike-photoreal-2.0"
model_prefix = "nsfw, photoreal style"
model = gr.Interface.load(model_path)

base_prompt = "give only one answer, limit is 36 words"

# Define the OpenAI prompt completion function
def generate_text(prompt):
    response = openai.Completion.create(
        model="text-davinci-003",
        prompt=f"{prompt}\n\nQ: {base_prompt}\nA:",
        #prompt=prompt,
        max_tokens=64,
        n=1,
        stop=None,
        temperature=0.5,
    )
    return response.choices[0].text.strip()

# Define the image generation function
def generate_image(prompt):
    # Generate text based on prompt
    text = generate_text(prompt)
    # Generate image based on text
    image = model(text)
    return text, image

# Define the Gradio interface
prompt_input = Textbox("Enter a prompt", lines=3)
text_output = Text("Output will appear here", lines=10)

image_output = Image()

iface = gr.Interface(
    generate_image,
    inputs=prompt_input,
    outputs=[text_output, image_output],
    title="Image Generator",
    description="Generates an image based on a prompt using OpenAI's GPT-3 and DALL-E models."
)

# Update the output boxes with the generated text and image
def update_output(text, image_url):
    # Get the current text in the output box
    current_text = text_output.value
    # Add the new text to the current text
    new_text = current_text + "\n\n" + text
    # Update the text output box with the new text
    text_output.update(new_text)

iface.interface_result_hooks = [update_output]

# Launch the interface
iface.launch()