LucMarcelPellinger commited on
Commit
934faae
·
verified ·
1 Parent(s): c22cbbd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -59
app.py CHANGED
@@ -5,9 +5,9 @@ import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
 
8
- import base64
9
- from PIL import Image
10
- import io
11
 
12
  from Gradio_UI import GradioUI
13
 
@@ -37,62 +37,6 @@ def get_current_time_in_timezone(timezone: str) -> str:
37
  except Exception as e:
38
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
39
 
40
- @tool
41
- def cartoon_story_tool(base64_image: str, story_prompt: str = "Create a 4-panel cartoon story.") -> str:
42
- """
43
- Generates a cartoon-style story from an input image and optional prompt.
44
-
45
- Args:
46
- base64_image: A base64-encoded image string (input frame).
47
- story_prompt: Optional text guiding the storyline (e.g., Create a 4-panel cartoon story with Scrooge McDuck as the main character.).
48
-
49
- Returns:
50
- A base64-encoded storyboard image or HTML with the sequence.
51
- """
52
- HF_TOKEN = "your_huggingface_token"
53
- headers = {"Authorization": f"Bearer {HF_TOKEN}"}
54
-
55
- # Decode input image
56
- image_bytes = base64.b64decode(base64_image.split(",")[-1])
57
- original_image = Image.open(io.BytesIO(image_bytes)).convert("RGB")
58
-
59
- # Placeholder: Call an image-to-image or inpainting model to create variations
60
- frames = []
61
- for i in range(4): # 4-panel story
62
- prompt = f"{story_prompt} Panel {i+1}"
63
- # Hugging Face Image-to-Image endpoint (example)
64
- response = requests.post(
65
- "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-2-1",
66
- headers=headers,
67
- files={"init_image": io.BytesIO(image_bytes)},
68
- data={"prompt": prompt, "strength": 0.6}
69
- )
70
-
71
- if response.status_code == 200:
72
- frame = Image.open(io.BytesIO(response.content)).convert("RGB")
73
- else:
74
- # fallback to original
75
- frame = original_image
76
-
77
- frames.append(frame)
78
-
79
- # Combine into a storyboard (horizontal strip)
80
- widths, heights = zip(*(img.size for img in frames))
81
- total_width = sum(widths)
82
- max_height = max(heights)
83
- storyboard = Image.new('RGB', (total_width, max_height))
84
-
85
- x_offset = 0
86
- for img in frames:
87
- storyboard.paste(img, (x_offset, 0))
88
- x_offset += img.size[0]
89
-
90
- # Encode storyboard to base64
91
- buffered = io.BytesIO()
92
- storyboard.save(buffered, format="PNG")
93
- encoded_story = base64.b64encode(buffered.getvalue()).decode("utf-8")
94
-
95
- return f"data:image/png;base64,{encoded_story}"
96
 
97
  final_answer = FinalAnswerTool()
98
 
 
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
 
8
+ #import base64
9
+ #from PIL import Image
10
+ #import io
11
 
12
  from Gradio_UI import GradioUI
13
 
 
37
  except Exception as e:
38
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
  final_answer = FinalAnswerTool()
42