Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- cromicrafter_chatbot.py +36 -0
- image_generator.py +9 -0
- text_generator.py +17 -0
cromicrafter_chatbot.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from text_generator import generate_comic_script
|
| 3 |
+
from image_generator import generate_comic_panel
|
| 4 |
+
|
| 5 |
+
def chatbot_response(user_input, history):
|
| 6 |
+
"""Processes user input to generate a comic story."""
|
| 7 |
+
if "start" in user_input.lower():
|
| 8 |
+
return "Welcome to Cromicrafter AI! Describe your comic idea."
|
| 9 |
+
|
| 10 |
+
if "generate" in user_input.lower():
|
| 11 |
+
history.append(("User", user_input))
|
| 12 |
+
|
| 13 |
+
# Sample story details (In a real setup, extract from user input)
|
| 14 |
+
character = "Detective Robo"
|
| 15 |
+
supporting_character = "AI Assistant Aida"
|
| 16 |
+
setting = "Cyberpunk City"
|
| 17 |
+
tone = "Mysterious"
|
| 18 |
+
|
| 19 |
+
# Generate script
|
| 20 |
+
script = generate_comic_script(character, supporting_character, setting, tone)
|
| 21 |
+
history.append(("Cromicrafter AI", script))
|
| 22 |
+
|
| 23 |
+
# Generate images for each panel
|
| 24 |
+
panels = []
|
| 25 |
+
for i, panel in enumerate(script.split("Panel")[1:]):
|
| 26 |
+
prompt = f"Comic panel: {panel.strip()}"
|
| 27 |
+
img_path = generate_comic_panel(prompt, f"output/panel_{i+1}.png")
|
| 28 |
+
panels.append(img_path)
|
| 29 |
+
|
| 30 |
+
return script, panels
|
| 31 |
+
|
| 32 |
+
return "Type 'generate' to create a comic or 'start' to begin!"
|
| 33 |
+
|
| 34 |
+
# Create Gradio chatbot interface
|
| 35 |
+
chatbot_ui = gr.ChatInterface(chatbot_response)
|
| 36 |
+
chatbot_ui.launch()
|
image_generator.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from PIL import Image, ImageDraw
|
| 2 |
+
|
| 3 |
+
def generate_comic_panel(prompt, output_path):
|
| 4 |
+
"""Creates a simple placeholder image for the comic panel."""
|
| 5 |
+
img = Image.new("RGB", (500, 500), color=(255, 255, 255))
|
| 6 |
+
draw = ImageDraw.Draw(img)
|
| 7 |
+
draw.text((20, 250), prompt, fill=(0, 0, 0))
|
| 8 |
+
img.save(output_path)
|
| 9 |
+
return output_path
|
text_generator.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def generate_comic_script(character, supporting_character, setting, tone):
|
| 2 |
+
"""Generates a comic script based on input details."""
|
| 3 |
+
return f"""
|
| 4 |
+
Title: {character} & {supporting_character} - The {tone} Adventure
|
| 5 |
+
|
| 6 |
+
Panel 1: {setting}, {character} is looking for clues.
|
| 7 |
+
Dialogue: {character}: "Something is off here..."
|
| 8 |
+
|
| 9 |
+
Panel 2: {supporting_character} appears.
|
| 10 |
+
Dialogue: {supporting_character}: "{character}, I found something!"
|
| 11 |
+
|
| 12 |
+
Panel 3: A mysterious figure in the shadows.
|
| 13 |
+
Dialogue: Mysterious Figure: "You're too late..."
|
| 14 |
+
|
| 15 |
+
Panel 4: Action scene unfolds.
|
| 16 |
+
Dialogue: {character}: "We'll see about that!"
|
| 17 |
+
"""
|