Gertie01 thisisvaze commited on
Commit
25e184d
0 Parent(s):

Duplicate from thisisvaze/enhanced-dalle2

Browse files

Co-authored-by: Aaditya Vaze <thisisvaze@users.noreply.huggingface.co>

Files changed (4) hide show
  1. .gitattributes +34 -0
  2. README.md +14 -0
  3. app.py +102 -0
  4. requirements.txt +4 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Enhanced Dalle2
3
+ emoji: ⚡
4
+ colorFrom: indigo
5
+ colorTo: gray
6
+ sdk: gradio
7
+ sdk_version: 3.32.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: mit
11
+ duplicated_from: thisisvaze/enhanced-dalle2
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import requests
3
+ import urllib.parse
4
+ import json
5
+ import gradio as gr
6
+ from PIL import Image, ImageDraw, ImageFont
7
+ from io import BytesIO
8
+ import os
9
+
10
+ openai.api_key = os.environ["OPEN_AI_KEY"]
11
+
12
+
13
+
14
+ png_bytes_array = []
15
+ images = []
16
+
17
+ system_prompt = """Transcript of a dialog, where the User interacts with an Assistant named Stablediffy. Stablediffy knows much about prompt engineering for stable diffusion (an open-source image generation software). The User asks Stablediffy about prompts for stable diffusion Image Generation.
18
+
19
+ Possible keywords for stable diffusion: "cinematic, colorful background, concept art, dramatic lighting, high detail, highly detailed, hyper realistic, intricate, intricate sharp details, octane render, smooth, studio lighting, trending on artstation, landscape, scenery, cityscape, underwater, salt flat, tundra, jungle, desert mountain, ocean, beach, lake, waterfall, ripples, swirl, waves, avenue, horizon, pasture, plateau, garden, fields, floating island, forest, cloud forest, grasslands, flower field, flower ocean, volcano, cliff, snowy mountain
20
+ city, cityscape, street, downtown"
21
+
22
+ -- Transcript --
23
+
24
+ USER: suggest a prompt for a young girl from Swiss sitting by the window with headphones on
25
+ ASSISTANT: gorgeous young Swiss girl sitting by window with headphones on, wearing white bra with translucent shirt over, soft lips, beach blonde hair, octane render, unreal engine, photograph, realistic skin texture, photorealistic, hyper realism, highly detailed, 85mm portrait photography, award winning, hard rim lighting photography
26
+
27
+ USER: suggest a prompt for an mysterious city
28
+ ASSISTANT: Mysterious city, cityscape, urban, downtown, street, noir style, cinematic lightning, dramatic lightning, intricate, sharp details, octane render, unreal engine, highly detailed, night scene, dark lighting, gritty atmosphere
29
+
30
+ USER: suggest a prompt for a high quality render of a car in 1950
31
+ ASSISTANT: Car in 1950, highly detailed, classic car, 1950's, highly detailed, dramatic lightning, cinematic lightning, unreal engine
32
+
33
+ USER:"""
34
+
35
+ def get_modified_text_response(user_query):
36
+ try:
37
+ response = openai.ChatCompletion.create(
38
+ model="gpt-3.5-turbo",
39
+ messages=[{"role": "system", "content": system_prompt},
40
+ {"role": "user", "content": "suggest a prompt for" + user_query}]
41
+ )
42
+ res = response["choices"][0]["message"]["content"].replace('\'', '')
43
+ print(res)
44
+ return res
45
+ except:
46
+ return "no gpt response"
47
+
48
+ def text_to_image(text, selected_value):
49
+ global png_bytes_array
50
+ images = []
51
+ if(selected_value == "New"):
52
+ png_bytes_array = []
53
+ image_urls = generate_image(text)
54
+ for img in image_urls:
55
+ response = requests.get(img['url'])
56
+ image = Image.open(BytesIO(response.content))
57
+ images.append(image)
58
+ bytesIO = BytesIO()
59
+ image.save(bytesIO, format="PNG")
60
+ png_bytes = bytesIO.getvalue()
61
+ png_bytes_array.append(png_bytes)
62
+ return images
63
+
64
+ else:
65
+ index = int(selected_value[-1])
66
+ image_urls = variation_image(png_bytes_array[index])
67
+ for img in image_urls:
68
+ response = requests.get(img['url'])
69
+ image = Image.open(BytesIO(response.content))
70
+ images.append(image)
71
+ return images
72
+
73
+ def variation_image(image):
74
+ response = openai.Image.create_variation(
75
+ image = image,
76
+ n=4,
77
+ size="1024x1024"
78
+ )
79
+ #print(response)
80
+ #image_url = response['data'][0]['url']
81
+ return response['data']
82
+ def generate_image(prompt):
83
+ better_prompt = get_modified_text_response(prompt)
84
+ response = openai.Image.create(
85
+ prompt=better_prompt,
86
+ n=4,
87
+ size="1024x1024"
88
+ )
89
+
90
+ return response['data']
91
+ def main():
92
+ radio_buttons = gr.inputs.Radio(["New", "Var0","Var1", "Var2", "Var3"], label="Select a variation option")
93
+ out = gr.Gallery(
94
+ label="Generated images", show_label=False, elem_id="gallery"
95
+ ).style(columns=[2], rows=[2], object_fit="contain", height="auto")
96
+ iface = gr.Interface(fn=text_to_image, inputs=["text",radio_buttons],
97
+ #outputs=gr.Gallery([gr.Image(type="pil").style(height=300,width=300),gr.Image(type="pil").style(height=300,width=300),gr.Image(type="pil").style(height=300,width=300),gr.Image(type="pil").style(height=300,width=300)]))
98
+ outputs = out)
99
+ iface.launch()
100
+
101
+ if __name__ == "__main__":
102
+ main()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ openai
2
+ requests
3
+ gradio
4
+ pillow