Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -21,6 +21,24 @@ translator = pipeline(
|
|
21 |
device=device
|
22 |
)
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
# Function to generate images based on the image's caption
|
25 |
def generate_image_and_translate(image, num_images=1):
|
26 |
# Generate caption in English from the uploaded image
|
@@ -41,24 +59,20 @@ def generate_image_and_translate(image, num_images=1):
|
|
41 |
|
42 |
# Set up the Gradio interface
|
43 |
interface = gr.Interface(
|
44 |
-
fn=generate_image_and_translate,
|
45 |
inputs=[
|
46 |
-
gr.Image(type="pil", label="Upload Image"),
|
47 |
-
gr.Slider(minimum=1, maximum=10, label="Number of Images", value=1, step=1)
|
48 |
],
|
49 |
outputs=[
|
50 |
-
gr.Gallery(label="Generated Images"),
|
51 |
-
gr.Textbox(label="Generated Caption (English)", interactive=False),
|
52 |
-
gr.Textbox(label="Translated Caption (Arabic)", interactive=False)
|
53 |
],
|
54 |
-
title="Image Generation and
|
55 |
-
description="Upload an image to
|
56 |
-
theme='freddyaboulton/dracula_revamped'
|
57 |
)
|
58 |
|
59 |
-
if __name__ == "__main__":
|
60 |
-
interface.launch()
|
61 |
-
|
62 |
-
|
63 |
# Launch the Gradio application
|
64 |
interface.launch()
|
|
|
21 |
device=device
|
22 |
)
|
23 |
|
24 |
+
# Function to generate images based on the image's caption
|
25 |
+
def generate_image_and_translate(image, num_images=1):
|
26 |
+
# Generate caption in English from the uploaded image
|
27 |
+
caption_en = caption_image(image)[0]['generated_text']
|
28 |
+
|
29 |
+
# Translate the English caption to Arabic
|
30 |
+
caption_ar = translator(caption_en, src_lang="eng_Latn", tgt_lang="arb_Arab")[0]['translation_text']
|
31 |
+
|
32 |
+
generated_images = []
|
33 |
+
|
34 |
+
# Generate the specified number of images based on the English caption
|
35 |
+
for _ in range(num_images):
|
36 |
+
generated_image = sd_pipeline(prompt=caption_en).images[0]
|
37 |
+
generated_images.append(generated_image)
|
38 |
+
|
39 |
+
# Return the generated images along with both captions
|
40 |
+
return generated_images, caption_en, caption_ar
|
41 |
+
|
42 |
# Function to generate images based on the image's caption
|
43 |
def generate_image_and_translate(image, num_images=1):
|
44 |
# Generate caption in English from the uploaded image
|
|
|
59 |
|
60 |
# Set up the Gradio interface
|
61 |
interface = gr.Interface(
|
62 |
+
fn=generate_image_and_translate, # Function to call when processing input
|
63 |
inputs=[
|
64 |
+
gr.Image(type="pil", label="π€ Upload Image"), # Input for image upload
|
65 |
+
gr.Slider(minimum=1, maximum=10, label="π’ Number of Images", value=1, step=1) # Slider to select number of images
|
66 |
],
|
67 |
outputs=[
|
68 |
+
gr.Gallery(label="πΌοΈ Generated Images"),
|
69 |
+
gr.Textbox(label="π Generated Caption (English)", interactive=False),
|
70 |
+
gr.Textbox(label="π Translated Caption (Arabic)", interactive=False)
|
71 |
],
|
72 |
+
title="Image Generation and Captioning", # Title of the interface
|
73 |
+
description="Upload an image to extract a caption and display it in both Arabic and English. Then, a new image will be generated based on that caption.", # Description
|
74 |
+
theme='freddyaboulton/dracula_revamped' # Determine theme
|
75 |
)
|
76 |
|
|
|
|
|
|
|
|
|
77 |
# Launch the Gradio application
|
78 |
interface.launch()
|