Andre commited on
Commit
e1eaf41
·
1 Parent(s): 1b4b7ae
Files changed (1) hide show
  1. colab.ipynb +161 -0
colab.ipynb ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "# Import necessary libraries\n",
10
+ "import ipywidgets as widgets\n",
11
+ "from IPython.display import display, clear_output\n",
12
+ "from img_gen_logic import generate_image\n",
13
+ "from config import models, prompts\n",
14
+ "\n",
15
+ "# Dropdown menu for model selection\n",
16
+ "model_dropdown = widgets.Dropdown(\n",
17
+ " options=[(model[\"alias\"], model[\"name\"]) for model in models],\n",
18
+ " description=\"Select Model:\",\n",
19
+ " style={\"description_width\": \"initial\"}\n",
20
+ ")\n",
21
+ "\n",
22
+ "# Dropdown menu for prompt selection\n",
23
+ "prompt_dropdown = widgets.Dropdown(\n",
24
+ " options=[(prompt[\"alias\"], prompt[\"text\"]) for prompt in prompts],\n",
25
+ " description=\"Select Prompt:\",\n",
26
+ " style={\"description_width\": \"initial\"}\n",
27
+ ")\n",
28
+ "\n",
29
+ "# Dropdown menu for team selection\n",
30
+ "team_dropdown = widgets.Dropdown(\n",
31
+ " options=[\"Red\", \"Blue\"],\n",
32
+ " description=\"Select Team:\",\n",
33
+ " style={\"description_width\": \"initial\"}\n",
34
+ ")\n",
35
+ "\n",
36
+ "# Input for height\n",
37
+ "height_input = widgets.IntText(\n",
38
+ " value=360,\n",
39
+ " description=\"Height:\",\n",
40
+ " style={\"description_width\": \"initial\"}\n",
41
+ ")\n",
42
+ "\n",
43
+ "# Input for width\n",
44
+ "width_input = widgets.IntText(\n",
45
+ " value=640,\n",
46
+ " description=\"Width:\",\n",
47
+ " style={\"description_width\": \"initial\"}\n",
48
+ ")\n",
49
+ "\n",
50
+ "# Input for number of inference steps\n",
51
+ "num_inference_steps_input = widgets.IntSlider(\n",
52
+ " value=20,\n",
53
+ " min=10,\n",
54
+ " max=100,\n",
55
+ " step=1,\n",
56
+ " description=\"Inference Steps:\",\n",
57
+ " style={\"description_width\": \"initial\"}\n",
58
+ ")\n",
59
+ "\n",
60
+ "# Input for guidance scale\n",
61
+ "guidance_scale_input = widgets.FloatSlider(\n",
62
+ " value=2,\n",
63
+ " min=1.0,\n",
64
+ " max=20.0,\n",
65
+ " step=0.5,\n",
66
+ " description=\"Guidance Scale:\",\n",
67
+ " style={\"description_width\": \"initial\"}\n",
68
+ ")\n",
69
+ "\n",
70
+ "# Input for seed\n",
71
+ "seed_input = widgets.IntText(\n",
72
+ " value=random.randint(0, 1000000),\n",
73
+ " description=\"Seed:\",\n",
74
+ " style={\"description_width\": \"initial\"}\n",
75
+ ")\n",
76
+ "\n",
77
+ "# Checkbox to randomize seed\n",
78
+ "randomize_seed_checkbox = widgets.Checkbox(\n",
79
+ " value=True,\n",
80
+ " description=\"Randomize Seed\",\n",
81
+ " style={\"description_width\": \"initial\"}\n",
82
+ ")\n",
83
+ "\n",
84
+ "# Text box for custom prompt\n",
85
+ "custom_prompt_input = widgets.Textarea(\n",
86
+ " value=\"\",\n",
87
+ " placeholder=\"Enter your custom prompt (up to 200 characters)...\",\n",
88
+ " description=\"Custom Prompt:\",\n",
89
+ " style={\"description_width\": \"initial\"},\n",
90
+ " layout=widgets.Layout(width=\"500px\", height=\"80px\")\n",
91
+ ")\n",
92
+ "\n",
93
+ "# Button to generate image\n",
94
+ "generate_button = widgets.Button(\n",
95
+ " description=\"Generate Image\",\n",
96
+ " button_style=\"success\"\n",
97
+ ")\n",
98
+ "\n",
99
+ "# Output area to display the image\n",
100
+ "output = widgets.Output()\n",
101
+ "\n",
102
+ "# Function to handle button click event\n",
103
+ "def on_generate_button_clicked(b):\n",
104
+ " with output:\n",
105
+ " clear_output(wait=True) # Clear previous output\n",
106
+ " selected_prompt = prompt_dropdown.value\n",
107
+ " selected_team = team_dropdown.value\n",
108
+ " selected_model = model_dropdown.value\n",
109
+ " height = height_input.value\n",
110
+ " width = width_input.value\n",
111
+ " num_inference_steps = num_inference_steps_input.value\n",
112
+ " guidance_scale = guidance_scale_input.value\n",
113
+ " seed = seed_input.value\n",
114
+ " custom_prompt = custom_prompt_input.value\n",
115
+ "\n",
116
+ " # Debug: Show selected parameters\n",
117
+ " print(f\"Selected Model: {model_dropdown.label}\")\n",
118
+ " print(f\"Selected Prompt: {prompt_dropdown.label}\")\n",
119
+ " print(f\"Selected Team: {selected_team}\")\n",
120
+ " print(f\"Height: {height}\")\n",
121
+ " print(f\"Width: {width}\")\n",
122
+ " print(f\"Inference Steps: {num_inference_steps}\")\n",
123
+ " print(f\"Guidance Scale: {guidance_scale}\")\n",
124
+ " print(f\"Seed: {seed}\")\n",
125
+ " print(f\"Custom Prompt: {custom_prompt}\")\n",
126
+ "\n",
127
+ " # Generate the image\n",
128
+ " image, message = generate_image(selected_prompt, selected_team, selected_model, height, width, num_inference_steps, guidance_scale, seed, custom_prompt)\n",
129
+ "\n",
130
+ " if isinstance(image, str):\n",
131
+ " print(image)\n",
132
+ " else:\n",
133
+ " # Debug: Indicate that the image is being displayed and saved\n",
134
+ " print(\"Image generated successfully!\")\n",
135
+ " print(\"Displaying image...\")\n",
136
+ "\n",
137
+ " # Display the image in the notebook\n",
138
+ " display(image)\n",
139
+ "\n",
140
+ "# Attach the button click event handler\n",
141
+ "generate_button.on_click(on_generate_button_clicked)\n",
142
+ "\n",
143
+ "# Display the widgets\n",
144
+ "display(prompt_dropdown, team_dropdown, model_dropdown, custom_prompt_input, generate_button, output)"
145
+ ]
146
+ }
147
+ ],
148
+ "metadata": {
149
+ "kernelspec": {
150
+ "display_name": "Python 3",
151
+ "language": "python",
152
+ "name": "python3"
153
+ },
154
+ "language_info": {
155
+ "name": "python",
156
+ "version": "3.12.0"
157
+ }
158
+ },
159
+ "nbformat": 4,
160
+ "nbformat_minor": 2
161
+ }