Spaces:
Sleeping
Sleeping
File size: 2,587 Bytes
d9bfb92 99e5347 d9bfb92 69dceec d9bfb92 69dceec 99e5347 69dceec 99e5347 69dceec d9bfb92 69dceec f683195 69dceec f683195 69dceec f8213d1 69dceec f683195 69dceec d03f0cb 69dceec 99e5347 d03f0cb f8213d1 69dceec 1ae8848 9ba4710 f8213d1 69dceec f683195 69dceec c84b537 69dceec d03f0cb 69dceec d03f0cb 69dceec 99e5347 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | import gradio as gr
from PIL import Image, ImageDraw, ImageFont
import random
# Set default banner size for LinkedIn
BANNER_WIDTH = 1584
BANNER_HEIGHT = 396
# Use a common system font (change if needed)
FONT_PATH = "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf"
# --- AI-like Suggestions ---
sample_texts = [
"Open to Work",
"UX Designer",
"Data Scientist",
"Product Manager",
"Software Engineer",
"AI Researcher",
]
def suggest_text():
return random.choice(sample_texts)
# --- Handle Click ---
click_position = [None, None]
def record_click(evt: gr.SelectData):
global click_position
click_position = [evt.index[0], evt.index[1]]
return f"[{click_position[0]}, {click_position[1]}]"
# --- Generate Banner with Overlaid Text ---
def generate_banner(image, text, font_size, color):
if image is None:
print("No image uploaded.")
return None
# Resize to LinkedIn banner size
image = image.resize((BANNER_WIDTH, BANNER_HEIGHT))
if not click_position or None in click_position:
print("Click position not set.")
return image
draw = ImageDraw.Draw(image)
try:
font = ImageFont.truetype(FONT_PATH, font_size)
except Exception as e:
print("Font loading failed:", e)
font = ImageFont.load_default()
draw.text((click_position[0], click_position[1]), text, fill=color, font=font)
return image
# --- Gradio UI ---
with gr.Blocks() as demo:
gr.Markdown("🧰 **Job Banner Creator (LinkedIn-Ready)**")
with gr.Row():
with gr.Column():
image_input = gr.Image(label="Upload Background Image", type="pil")
# image_input.style(height=300)
with gr.Column():
click_display = gr.Textbox(label="Click Position")
with gr.Row():
text_input = gr.Textbox(label="Custom Text (e.g. 'Open to Work')")
suggest_btn = gr.Button("🎯 Suggest Text")
with gr.Row():
font_size_slider = gr.Slider(20, 120, step=1, value=48, label="Font Size")
text_color = gr.ColorPicker(label="Text Color", value="#000000")
generate_btn = gr.Button("✅ Generate Banner")
output_image = gr.Image(label="Preview (1584 x 396)")
# Events
suggest_btn.click(fn=suggest_text, outputs=text_input)
image_input.select(fn=record_click, outputs=click_display)
generate_btn.click(fn=generate_banner,
inputs=[image_input, text_input, font_size_slider, text_color],
outputs=output_image)
# --- Launch ---
demo.launch()
|