Update app.py
Browse files
app.py
CHANGED
@@ -1,34 +1,43 @@
|
|
1 |
-
|
2 |
-
import
|
|
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
|
7 |
-
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
-
|
9 |
-
# الحروف المقطعة
|
10 |
-
harf_muqattaat = ['أ', 'ل', 'م', 'ص', 'ر', 'ك', 'ه', 'ي', 'ع', 'ط', 'س', 'ح', 'ق', 'ن']
|
11 |
-
|
12 |
-
# وظيفة لتوليد كلمات باستخدام الحروف المقطعة
|
13 |
-
def generate_words_from_muqattaat():
|
14 |
-
# اختيار عدد عشوائي للحروف في الجملة
|
15 |
-
length = random.randint(2, len(harf_muqattaat)) # اختيار طول عشوائي بين 2 وطول القائمة
|
16 |
-
# اختيار مجموعة عشوائية من الحروف بدون تكرار
|
17 |
-
random.shuffle(harf_muqattaat)
|
18 |
-
# تكوين الجملة العشوائية من الحروف المقطعة
|
19 |
-
input_text = ''.join(harf_muqattaat[:length])
|
20 |
|
21 |
-
#
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
-
|
25 |
-
|
|
|
26 |
|
27 |
-
|
28 |
-
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
29 |
|
30 |
-
|
|
|
31 |
|
32 |
-
|
33 |
-
for _ in range(5):
|
34 |
-
print(generate_words_from_muqattaat())
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from PIL import Image
|
3 |
+
import rembg
|
4 |
|
5 |
+
# Function to handle image uploads, optional background removal, and collage generation
|
6 |
+
def process_images(images, remove_bg):
|
7 |
+
final_collage = Image.new("RGBA", (2480, 3508), (255, 255, 255, 0)) # A4 size transparent canvas
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
+
# Positioning each image onto the A4 canvas
|
10 |
+
x_offset = 0
|
11 |
+
y_offset = 0
|
12 |
+
for img in images:
|
13 |
+
img = Image.open(img)
|
14 |
+
|
15 |
+
# Optionally remove background
|
16 |
+
if remove_bg:
|
17 |
+
img = Image.open(rembg.remove(img))
|
18 |
+
|
19 |
+
# Resize the image if necessary
|
20 |
+
img.thumbnail((500, 500)) # Limit the size of each sticker for now
|
21 |
+
|
22 |
+
# Paste the image onto the canvas
|
23 |
+
final_collage.paste(img, (x_offset, y_offset), img)
|
24 |
+
|
25 |
+
# Update position for next image (for simplicity stacking vertically)
|
26 |
+
y_offset += img.height
|
27 |
+
|
28 |
+
return final_collage
|
29 |
+
|
30 |
+
# Gradio interface
|
31 |
+
with gr.Blocks() as demo:
|
32 |
+
gr.Markdown("## Sticker Collage Creator (A4)")
|
33 |
|
34 |
+
with gr.Row():
|
35 |
+
images = gr.File(label="Upload your images", file_types=["image"], multiple=True)
|
36 |
+
remove_bg = gr.Checkbox(label="Remove background?", value=True)
|
37 |
|
38 |
+
output = gr.Image(label="Collage", type="pil")
|
|
|
39 |
|
40 |
+
submit = gr.Button("Create Collage")
|
41 |
+
submit.click(process_images, inputs=[images, remove_bg], outputs=output)
|
42 |
|
43 |
+
demo.launch()
|
|
|
|