Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
-
import torch
|
| 4 |
from PIL import Image, ImageDraw, ImageFont
|
| 5 |
import io, zipfile
|
| 6 |
import mediapipe as mp
|
| 7 |
import numpy as np
|
| 8 |
|
| 9 |
# ----------------------
|
| 10 |
-
#
|
| 11 |
# ----------------------
|
| 12 |
-
|
| 13 |
-
"
|
| 14 |
-
|
| 15 |
-
)
|
| 16 |
|
| 17 |
# Mediapipe for character detection
|
| 18 |
mp_face = mp.solutions.face_detection.FaceDetection(model_selection=1, min_detection_confidence=0.5)
|
|
@@ -96,7 +96,7 @@ def add_speech_bubbles(img, bubbles, character_positions=None):
|
|
| 96 |
return img
|
| 97 |
|
| 98 |
def generate_comic(title, story, pages, panels, art_style, theme, dialogues, explicit):
|
| 99 |
-
"""Generate AI comic panels with bubbles."""
|
| 100 |
comic_panels = []
|
| 101 |
panels = int(panels)
|
| 102 |
panel_dialogues = dialogues.split("\n") if dialogues else [""] * panels
|
|
@@ -104,9 +104,15 @@ def generate_comic(title, story, pages, panels, art_style, theme, dialogues, exp
|
|
| 104 |
for i in range(panels):
|
| 105 |
prompt = f"{story}, {art_style} comic style, {theme} theme, colorful, detailed, panel {i+1}"
|
| 106 |
if explicit:
|
| 107 |
-
prompt += ", include blood, gore, offensive language,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
-
img = pipe(prompt, guidance_scale=7.5).images[0]
|
| 110 |
character_positions = detect_characters(img)
|
| 111 |
|
| 112 |
# Prepare bubbles
|
|
|
|
| 1 |
+
import os
|
| 2 |
import gradio as gr
|
| 3 |
+
from huggingface_hub import InferenceClient
|
|
|
|
| 4 |
from PIL import Image, ImageDraw, ImageFont
|
| 5 |
import io, zipfile
|
| 6 |
import mediapipe as mp
|
| 7 |
import numpy as np
|
| 8 |
|
| 9 |
# ----------------------
|
| 10 |
+
# Hugging Face Inference Client
|
| 11 |
# ----------------------
|
| 12 |
+
client = InferenceClient(
|
| 13 |
+
provider="fal-ai",
|
| 14 |
+
api_key=os.environ.get("HF_TOKEN", "")
|
| 15 |
+
)
|
| 16 |
|
| 17 |
# Mediapipe for character detection
|
| 18 |
mp_face = mp.solutions.face_detection.FaceDetection(model_selection=1, min_detection_confidence=0.5)
|
|
|
|
| 96 |
return img
|
| 97 |
|
| 98 |
def generate_comic(title, story, pages, panels, art_style, theme, dialogues, explicit):
|
| 99 |
+
"""Generate AI comic panels with bubbles using Hugging Face Inference API."""
|
| 100 |
comic_panels = []
|
| 101 |
panels = int(panels)
|
| 102 |
panel_dialogues = dialogues.split("\n") if dialogues else [""] * panels
|
|
|
|
| 104 |
for i in range(panels):
|
| 105 |
prompt = f"{story}, {art_style} comic style, {theme} theme, colorful, detailed, panel {i+1}"
|
| 106 |
if explicit:
|
| 107 |
+
prompt += ", include blood, gore, offensive language, dramatic action"
|
| 108 |
+
|
| 109 |
+
# Generate image via HF API
|
| 110 |
+
image = client.text_to_image(
|
| 111 |
+
prompt,
|
| 112 |
+
model="stabilityai/stable-diffusion-3.5-large"
|
| 113 |
+
)
|
| 114 |
+
img = image.convert("RGB")
|
| 115 |
|
|
|
|
| 116 |
character_positions = detect_characters(img)
|
| 117 |
|
| 118 |
# Prepare bubbles
|