Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -21,7 +21,7 @@ def draw_lattice_grid(draw, width, height, spacing=100, color=(235, 235, 235)):
|
|
21 |
# Draw vertical lines
|
22 |
for x in range(0, width, spacing):
|
23 |
draw.line([(x, 0), (x, height)], fill=color, width=2)
|
24 |
-
# Draw horizontal lines
|
25 |
for y in range(0, height, spacing):
|
26 |
draw.line([(0, y), (width, y)], fill=color, width=2)
|
27 |
|
@@ -240,89 +240,111 @@ Every midnight, as the city slept, the clock would chime, not with bells, but wi
|
|
240 |
|
241 |
One day, a young girl with eyes as curious as a cat's wandered into his shop. She wasn't interested in the shiny new watches but was drawn to the grandfather clock. "What's its story?" she asked, her voice soft. Alistair smiled, for he knew he had found the next guardian of the stories. The legacy of the whispering clock would live on."""
|
242 |
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
[
|
285 |
-
|
286 |
-
|
287 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
288 |
|
289 |
if __name__ == "__main__":
|
290 |
-
|
291 |
-
|
292 |
-
from contextlib import asynccontextmanager
|
293 |
|
294 |
-
#
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
#
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
quiet
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
316 |
try:
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
|
|
|
|
|
21 |
# Draw vertical lines
|
22 |
for x in range(0, width, spacing):
|
23 |
draw.line([(x, 0), (x, height)], fill=color, width=2)
|
24 |
+
# Draw horizontal lines
|
25 |
for y in range(0, height, spacing):
|
26 |
draw.line([(0, y), (width, y)], fill=color, width=2)
|
27 |
|
|
|
240 |
|
241 |
One day, a young girl with eyes as curious as a cat's wandered into his shop. She wasn't interested in the shiny new watches but was drawn to the grandfather clock. "What's its story?" she asked, her voice soft. Alistair smiled, for he knew he had found the next guardian of the stories. The legacy of the whispering clock would live on."""
|
242 |
|
243 |
+
def create_app():
|
244 |
+
"""Create and configure the Gradio app with better error handling."""
|
245 |
+
|
246 |
+
# Create the demo with enhanced error handling
|
247 |
+
demo = gr.Interface(
|
248 |
+
fn=text_to_images_mcp,
|
249 |
+
inputs=[
|
250 |
+
gr.Textbox(
|
251 |
+
value=sample_text,
|
252 |
+
lines=10,
|
253 |
+
max_lines=20,
|
254 |
+
label="Text Content",
|
255 |
+
placeholder="Enter your long-form text here (max 10,000 characters)..."
|
256 |
+
),
|
257 |
+
gr.Dropdown(
|
258 |
+
choices=['plain', 'lines', 'dots', 'grid'],
|
259 |
+
value='lines',
|
260 |
+
label="Background Style",
|
261 |
+
info="Choose the background style for your images"
|
262 |
+
),
|
263 |
+
gr.Textbox(
|
264 |
+
value="",
|
265 |
+
label="Custom Font Path (Optional)",
|
266 |
+
placeholder="/path/to/your/font.ttf",
|
267 |
+
info="Leave empty to use system default font"
|
268 |
+
)
|
269 |
+
],
|
270 |
+
outputs=[
|
271 |
+
gr.Gallery(
|
272 |
+
label="Generated Images (Max 10 pages)",
|
273 |
+
show_label=True,
|
274 |
+
elem_id="gallery",
|
275 |
+
columns=2,
|
276 |
+
rows=2,
|
277 |
+
object_fit="contain",
|
278 |
+
height="auto",
|
279 |
+
show_download_button=True
|
280 |
+
)
|
281 |
+
],
|
282 |
+
title="π Text to Images Converter (MCP Compatible)",
|
283 |
+
description="Transform long-form text into a series of attractive, readable images. Simply paste your text, choose a background style, and preview the generated images. You can download individual images by clicking on them. Limited to 10,000 characters and 10 pages for optimal performance. This app functions as an MCP server for LLM integration.",
|
284 |
+
examples=[
|
285 |
+
[sample_text, 'lines', ''],
|
286 |
+
[sample_text, 'dots', ''],
|
287 |
+
[sample_text, 'grid', ''],
|
288 |
+
[sample_text, 'plain', '']
|
289 |
+
],
|
290 |
+
cache_examples=False,
|
291 |
+
show_api=True
|
292 |
+
)
|
293 |
+
|
294 |
+
return demo
|
295 |
|
296 |
if __name__ == "__main__":
|
297 |
+
# Set up environment for MCP server
|
298 |
+
os.environ["GRADIO_MCP_SERVER"] = "True"
|
|
|
299 |
|
300 |
+
# Create the app
|
301 |
+
demo = create_app()
|
302 |
+
|
303 |
+
# Launch with multiple fallback strategies
|
304 |
+
launch_configs = [
|
305 |
+
# Strategy 1: Full MCP server with explicit settings
|
306 |
+
{
|
307 |
+
"mcp_server": True,
|
308 |
+
"server_name": "0.0.0.0",
|
309 |
+
"server_port": 7860,
|
310 |
+
"share": False,
|
311 |
+
"debug": False,
|
312 |
+
"show_error": False,
|
313 |
+
"quiet": True
|
314 |
+
},
|
315 |
+
# Strategy 2: Environment variable only
|
316 |
+
{
|
317 |
+
"server_name": "0.0.0.0",
|
318 |
+
"server_port": 7860,
|
319 |
+
"share": False,
|
320 |
+
"debug": False,
|
321 |
+
"show_error": False,
|
322 |
+
"quiet": True
|
323 |
+
},
|
324 |
+
# Strategy 3: Minimal configuration
|
325 |
+
{
|
326 |
+
"server_name": "0.0.0.0",
|
327 |
+
"server_port": 7860,
|
328 |
+
"share": False
|
329 |
+
},
|
330 |
+
# Strategy 4: Default configuration
|
331 |
+
{}
|
332 |
+
]
|
333 |
+
|
334 |
+
launched = False
|
335 |
+
for i, config in enumerate(launch_configs):
|
336 |
try:
|
337 |
+
print(f"Attempting launch strategy {i+1}...")
|
338 |
+
demo.launch(**config)
|
339 |
+
launched = True
|
340 |
+
print(f"Successfully launched with strategy {i+1}")
|
341 |
+
break
|
342 |
+
except Exception as e:
|
343 |
+
print(f"Launch strategy {i+1} failed: {e}")
|
344 |
+
if i < len(launch_configs) - 1:
|
345 |
+
print("Trying next strategy...")
|
346 |
+
continue
|
347 |
+
|
348 |
+
if not launched:
|
349 |
+
print("All launch strategies failed. Please check your environment and dependencies.")
|
350 |
+
print("You may need to install gradio[mcp] or update your gradio version.")
|