Spaces:
Running
Running
Commit
·
f9630b2
1
Parent(s):
42b79ab
Fix spaces
Browse files- README.md +16 -0
- app.py +7 -4
- src/visual_synthesizer.py +15 -2
- utils/config.py +0 -1
README.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
| 2 |
|
| 3 |
This project generates social media posts, including an image and a caption, from a user-provided text prompt. It leverages deep learning models for both text-to-image synthesis and text generation to create engaging content.
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
## How it Works
|
| 6 |
|
| 7 |
The process is orchestrated by the `main.py` script and follows these steps:
|
|
|
|
| 2 |
|
| 3 |
This project generates social media posts, including an image and a caption, from a user-provided text prompt. It leverages deep learning models for both text-to-image synthesis and text generation to create engaging content.
|
| 4 |
|
| 5 |
+
## Spaces
|
| 6 |
+
|
| 7 |
+
```
|
| 8 |
+
title: FromWordsToMedia
|
| 9 |
+
emoji: 🖼
|
| 10 |
+
colorFrom: purple
|
| 11 |
+
colorTo: red
|
| 12 |
+
sdk: gradio
|
| 13 |
+
sdk_version: 5.25.2
|
| 14 |
+
app_file: app.py
|
| 15 |
+
pinned: false
|
| 16 |
+
license: mit
|
| 17 |
+
short_description: Generates an image and a caption for social media posts
|
| 18 |
+
```
|
| 19 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 20 |
+
|
| 21 |
## How it Works
|
| 22 |
|
| 23 |
The process is orchestrated by the `main.py` script and follows these steps:
|
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
# External library imports
|
| 2 |
from datetime import datetime
|
| 3 |
import gradio as gr
|
|
|
|
| 4 |
|
| 5 |
# Internal imports
|
| 6 |
from src.visual_synthesizer import VisualSynthesizer
|
|
@@ -11,6 +12,11 @@ from utils.config import *
|
|
| 11 |
from utils.helpers import richify_prompt, save_caption, save_image
|
| 12 |
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
def compose(prompt: str, filename: str = "generated_post"):
|
| 15 |
"""
|
| 16 |
Main function to compose an Instagram post from a given prompt.
|
|
@@ -23,15 +29,11 @@ def compose(prompt: str, filename: str = "generated_post"):
|
|
| 23 |
timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
|
| 24 |
filename = f"{timestamp}_{filename}"
|
| 25 |
|
| 26 |
-
# Initialize the visual synthesizer
|
| 27 |
-
image_gen = VisualSynthesizer()
|
| 28 |
# Generate the image
|
| 29 |
image = image_gen.generate_image(prompt=richify_prompt(prompt))
|
| 30 |
# Save the image
|
| 31 |
image_path = save_image(image, filename=filename)
|
| 32 |
print(f"Image saved at: {image_path}")
|
| 33 |
-
# Create a caption for the post
|
| 34 |
-
text_gen = TextSynthesizer()
|
| 35 |
caption = text_gen.generate_caption(prompt=prompt)
|
| 36 |
# Save the caption
|
| 37 |
caption_path = save_caption(caption, filename=filename)
|
|
@@ -40,6 +42,7 @@ def compose(prompt: str, filename: str = "generated_post"):
|
|
| 40 |
|
| 41 |
|
| 42 |
if __name__ == '__main__':
|
|
|
|
| 43 |
iface = gr.Interface(
|
| 44 |
fn=compose,
|
| 45 |
inputs=gr.Textbox(lines=5, label="Prompt", placeholder="Enter your prompt here..."),
|
|
|
|
| 1 |
# External library imports
|
| 2 |
from datetime import datetime
|
| 3 |
import gradio as gr
|
| 4 |
+
import asyncio
|
| 5 |
|
| 6 |
# Internal imports
|
| 7 |
from src.visual_synthesizer import VisualSynthesizer
|
|
|
|
| 12 |
from utils.helpers import richify_prompt, save_caption, save_image
|
| 13 |
|
| 14 |
|
| 15 |
+
# Initialize the text and visual synthesizer
|
| 16 |
+
image_gen = VisualSynthesizer()
|
| 17 |
+
text_gen = TextSynthesizer()
|
| 18 |
+
|
| 19 |
+
|
| 20 |
def compose(prompt: str, filename: str = "generated_post"):
|
| 21 |
"""
|
| 22 |
Main function to compose an Instagram post from a given prompt.
|
|
|
|
| 29 |
timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
|
| 30 |
filename = f"{timestamp}_{filename}"
|
| 31 |
|
|
|
|
|
|
|
| 32 |
# Generate the image
|
| 33 |
image = image_gen.generate_image(prompt=richify_prompt(prompt))
|
| 34 |
# Save the image
|
| 35 |
image_path = save_image(image, filename=filename)
|
| 36 |
print(f"Image saved at: {image_path}")
|
|
|
|
|
|
|
| 37 |
caption = text_gen.generate_caption(prompt=prompt)
|
| 38 |
# Save the caption
|
| 39 |
caption_path = save_caption(caption, filename=filename)
|
|
|
|
| 42 |
|
| 43 |
|
| 44 |
if __name__ == '__main__':
|
| 45 |
+
|
| 46 |
iface = gr.Interface(
|
| 47 |
fn=compose,
|
| 48 |
inputs=gr.Textbox(lines=5, label="Prompt", placeholder="Enter your prompt here..."),
|
src/visual_synthesizer.py
CHANGED
|
@@ -43,9 +43,22 @@ class VisualSynthesizer:
|
|
| 43 |
# self.video_pipe.enable_model_cpu_offload()
|
| 44 |
|
| 45 |
|
| 46 |
-
def generate_image(self,
|
|
|
|
| 47 |
negative_prompt: str = "blurry, distorted, poorly drawn, watermark",
|
| 48 |
-
num_inference_steps: int = 50,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
image = self.image_pipe(prompt,
|
| 50 |
negative_prompt=negative_prompt,
|
| 51 |
num_inference_steps=num_inference_steps,
|
|
|
|
| 43 |
# self.video_pipe.enable_model_cpu_offload()
|
| 44 |
|
| 45 |
|
| 46 |
+
def generate_image(self,
|
| 47 |
+
prompt: str,
|
| 48 |
negative_prompt: str = "blurry, distorted, poorly drawn, watermark",
|
| 49 |
+
num_inference_steps: int = 50,
|
| 50 |
+
guidance_scale: float = 7.5):
|
| 51 |
+
"""
|
| 52 |
+
Generates an image from a text prompt.
|
| 53 |
+
Args:
|
| 54 |
+
prompt (str): Text prompt to guide image generation.
|
| 55 |
+
negative_prompt (str): Optional negative prompts to avoid certain features.
|
| 56 |
+
num_inference_steps (int): Number of inference steps for generation.
|
| 57 |
+
guidance_scale (float): Guidance scale for generation.
|
| 58 |
+
Returns:
|
| 59 |
+
PIL.Image: Generated image.
|
| 60 |
+
"""
|
| 61 |
+
# use the pipeline to generate an image based on the prompt and other parameters
|
| 62 |
image = self.image_pipe(prompt,
|
| 63 |
negative_prompt=negative_prompt,
|
| 64 |
num_inference_steps=num_inference_steps,
|
utils/config.py
CHANGED
|
@@ -17,7 +17,6 @@ VIDEO_MODEL_NAME = "cerspense/zeroscope_v2_XL" # Placeholder for video model
|
|
| 17 |
# Other models to try # Qwen/Qwen-Image # CompVis/stable-diffusion-v1-4
|
| 18 |
# "segmind/SSD-1B" # Or "kandinsky-community/kandinsky-3", "warp-ai/wuerstchen"
|
| 19 |
# Video generation models # cerspense/zeroscope_v2_576w # Wan‑Video/Wan2.1
|
| 20 |
-
DEVICE = "cuda" # Change to "cpu" if no GPU available
|
| 21 |
|
| 22 |
# Font path for overlay text
|
| 23 |
# FONT_PATH = "./fonts/arial.ttf"
|
|
|
|
| 17 |
# Other models to try # Qwen/Qwen-Image # CompVis/stable-diffusion-v1-4
|
| 18 |
# "segmind/SSD-1B" # Or "kandinsky-community/kandinsky-3", "warp-ai/wuerstchen"
|
| 19 |
# Video generation models # cerspense/zeroscope_v2_576w # Wan‑Video/Wan2.1
|
|
|
|
| 20 |
|
| 21 |
# Font path for overlay text
|
| 22 |
# FONT_PATH = "./fonts/arial.ttf"
|