Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,85 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
-
import time
|
3 |
-
import logging
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
logger = logging.getLogger(__name__)
|
8 |
-
|
9 |
-
def load_model(model_path):
|
10 |
-
logger.info(f"Attempting to load model from {model_path}...")
|
11 |
-
try:
|
12 |
-
# Try to load the model
|
13 |
-
logger.info("Before calling gr.load")
|
14 |
-
result = gr.load(model_path)
|
15 |
-
logger.info("After calling gr.load")
|
16 |
-
|
17 |
-
# Add extensive debugging information
|
18 |
-
logger.info(f"Model loaded. Result type: {type(result)}")
|
19 |
-
|
20 |
-
# If it's a tuple, inspect its contents
|
21 |
-
if isinstance(result, tuple):
|
22 |
-
logger.info(f"Result is a tuple of length {len(result)}")
|
23 |
-
for i, item in enumerate(result):
|
24 |
-
logger.info(f"Tuple item {i}: type={type(item)}")
|
25 |
-
|
26 |
-
# If the item has attributes, log them
|
27 |
-
if hasattr(item, "__dict__"):
|
28 |
-
logger.info(f"Item {i} attributes: {dir(item)}")
|
29 |
-
|
30 |
-
# If it's a complex object, try to get more info
|
31 |
-
try:
|
32 |
-
logger.info(f"Item {i} representation: {repr(item)}")
|
33 |
-
except:
|
34 |
-
logger.info(f"Could not get representation of item {i}")
|
35 |
-
|
36 |
-
logger.info(f"Successfully loaded demo from {model_path}.")
|
37 |
-
return result
|
38 |
-
except Exception as e:
|
39 |
-
logger.error(f"Failed to load demo from {model_path}: {e}")
|
40 |
-
# Get more detailed error information
|
41 |
-
import traceback
|
42 |
-
logger.error(f"Detailed error traceback: {traceback.format_exc()}")
|
43 |
-
return None
|
44 |
-
|
45 |
-
# Load the demo
|
46 |
-
demo = load_model("models/John6666/the-araminta-fv1-sdxl")
|
47 |
-
#demo = load_model("models/John6666/the-araminta-experiment-fv2-sdxl")
|
48 |
-
|
49 |
-
def generate_image(prompt, max_retries=5):
|
50 |
-
if demo is None:
|
51 |
-
return None, "Error: Demo failed to load."
|
52 |
-
|
53 |
-
for attempt in range(max_retries):
|
54 |
-
try:
|
55 |
-
logger.info(f"Attempt {attempt + 1}: Starting image generation with prompt: {prompt}")
|
56 |
-
start_time = time.time()
|
57 |
-
result = demo(prompt)
|
58 |
-
generation_time = time.time() - start_time
|
59 |
-
logger.info(f"Generation completed in {generation_time:.2f} seconds")
|
60 |
-
logger.info(result)
|
61 |
-
return result, f"Image generated successfully\nGeneration time: {generation_time:.2f} seconds"
|
62 |
-
except Exception as e:
|
63 |
-
logger.error(f"Error on attempt {attempt + 1}: {str(e)}")
|
64 |
-
if attempt < max_retries - 1:
|
65 |
-
logger.info(f"Retrying... ({attempt + 2}/{max_retries})")
|
66 |
-
else:
|
67 |
-
logger.error("Max retries reached. Giving up.")
|
68 |
-
return None, f"Failed to generate image after {max_retries} attempts. Last error: {str(e)}"
|
69 |
|
70 |
-
|
71 |
-
return None, "Unexpected error occurred"
|
72 |
-
|
73 |
-
iface = gr.Interface(
|
74 |
-
fn=generate_image,
|
75 |
-
inputs=gr.Textbox(label="Enter your prompt"),
|
76 |
-
outputs=[
|
77 |
-
gr.Image(label="Generated Image"),
|
78 |
-
gr.Textbox(label="Output Information", lines=5)
|
79 |
-
],
|
80 |
-
title="Text-to-Image Generation",
|
81 |
-
description="Enter a prompt to generate an image. The system will automatically retry up to 5 times if an error occurs."
|
82 |
-
)
|
83 |
-
|
84 |
-
logger.info("Launching the Gradio interface...")
|
85 |
-
iface.launch()
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
+
with gr.Blocks(fill_height=True) as demo:
|
4 |
+
gr.load("models/John6666/the-araminta-fv1-sdxl", provider="hf-inference")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|