Update app.py
Browse files
app.py
CHANGED
@@ -24,45 +24,47 @@ object_bboxes_list = []
|
|
24 |
# Function to add or update the prompt in the list
|
25 |
def submit_prompt(prompt):
|
26 |
if object_classes_list:
|
27 |
-
object_classes_list[0] = prompt
|
28 |
else:
|
29 |
-
object_classes_list.insert(0, prompt)
|
30 |
|
31 |
if not object_bboxes_list:
|
32 |
-
object_bboxes_list.insert(0, "0,0,512,512")
|
33 |
|
34 |
combined_list = [[cls, bbox] for cls, bbox in zip(object_classes_list, object_bboxes_list)]
|
35 |
-
return combined_list, gr.update(interactive=False)
|
36 |
|
37 |
# Function to add a new object with validation
|
38 |
def add_object(object_class, bbox):
|
39 |
try:
|
40 |
-
# Split and convert bbox string into integers
|
41 |
x1, y1, x2, y2 = map(int, bbox.split(","))
|
42 |
-
|
43 |
-
|
44 |
-
if x2 < x1 or y2 < y1:
|
45 |
-
return "Error: x2 cannot be less than x1 and y2 cannot be less than y1.", []
|
46 |
-
if x1 < 0 or y1 < 0 or x2 > 512 or y2 > 512:
|
47 |
-
return "Error: Coordinates must be between 0 and 512.", []
|
48 |
-
|
49 |
-
# If validation passes, add to the lists
|
50 |
object_classes_list.append(object_class)
|
51 |
object_bboxes_list.append(bbox)
|
52 |
combined_list = [[cls, bbox] for cls, bbox in zip(object_classes_list, object_bboxes_list)]
|
53 |
return combined_list
|
54 |
-
|
55 |
except ValueError:
|
56 |
return "Error: Invalid input format. Use x1,y1,x2,y2.", []
|
57 |
|
58 |
-
# Gradio UI
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
gr.Markdown("# Text-to-Image Generator with Object Addition")
|
61 |
|
62 |
-
# Put prompt and submit button
|
63 |
with gr.Row():
|
64 |
-
prompt = gr.Textbox(label="Prompt", placeholder="Enter your prompt here",
|
65 |
-
submit_button = gr.Button("Submit",
|
66 |
|
67 |
# Always visible DataFrame
|
68 |
objects_display = gr.Dataframe(
|
|
|
24 |
# Function to add or update the prompt in the list
|
25 |
def submit_prompt(prompt):
|
26 |
if object_classes_list:
|
27 |
+
object_classes_list[0] = prompt
|
28 |
else:
|
29 |
+
object_classes_list.insert(0, prompt)
|
30 |
|
31 |
if not object_bboxes_list:
|
32 |
+
object_bboxes_list.insert(0, "0,0,512,512")
|
33 |
|
34 |
combined_list = [[cls, bbox] for cls, bbox in zip(object_classes_list, object_bboxes_list)]
|
35 |
+
return combined_list, gr.update(interactive=False)
|
36 |
|
37 |
# Function to add a new object with validation
|
38 |
def add_object(object_class, bbox):
|
39 |
try:
|
|
|
40 |
x1, y1, x2, y2 = map(int, bbox.split(","))
|
41 |
+
if x2 < x1 or y2 < y1 or x1 < 0 or y1 < 0 or x2 > 512 or y2 > 512:
|
42 |
+
return "Error: Invalid coordinates.", []
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
object_classes_list.append(object_class)
|
44 |
object_bboxes_list.append(bbox)
|
45 |
combined_list = [[cls, bbox] for cls, bbox in zip(object_classes_list, object_bboxes_list)]
|
46 |
return combined_list
|
|
|
47 |
except ValueError:
|
48 |
return "Error: Invalid input format. Use x1,y1,x2,y2.", []
|
49 |
|
50 |
+
# Gradio UI with custom CSS
|
51 |
+
css = """
|
52 |
+
#custom-prompt {
|
53 |
+
width: 400px; /* Set the width of the prompt input box */
|
54 |
+
}
|
55 |
+
#custom-button {
|
56 |
+
width: 150px; /* Set the width of the submit button */
|
57 |
+
height: 38px; /* Set the height of the submit button */
|
58 |
+
}
|
59 |
+
"""
|
60 |
+
|
61 |
+
with gr.Blocks(css=css) as demo:
|
62 |
gr.Markdown("# Text-to-Image Generator with Object Addition")
|
63 |
|
64 |
+
# Put prompt and submit button in the same row and apply custom styles
|
65 |
with gr.Row():
|
66 |
+
prompt = gr.Textbox(label="Prompt", placeholder="Enter your prompt here", elem_id="custom-prompt")
|
67 |
+
submit_button = gr.Button("Submit Prompt", elem_id="custom-button")
|
68 |
|
69 |
# Always visible DataFrame
|
70 |
objects_display = gr.Dataframe(
|