aiqtech commited on
Commit
7ab58cc
·
verified ·
1 Parent(s): 770e58c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -10
app.py CHANGED
@@ -69,17 +69,25 @@ def run_single_image_logic(prompt: str, image_path: Optional[str] = None, progre
69
 
70
  progress(0.8, desc="🖼️ 마무리 중...")
71
 
72
- # Handle the output
73
  if output:
74
- # If output is a FileOutput object, get the URL
75
  if hasattr(output, 'url'):
76
- image_url = output.url()
 
 
77
  elif isinstance(output, str):
78
  image_url = output
 
79
  elif isinstance(output, list) and len(output) > 0:
80
- image_url = output[0]
 
 
 
 
 
81
  else:
82
- raise ValueError("Unexpected output format from Replicate")
83
 
84
  # Download the image from URL
85
  response = requests.get(image_url)
@@ -97,6 +105,8 @@ def run_single_image_logic(prompt: str, image_path: Optional[str] = None, progre
97
  except Exception as e:
98
  print(f"Error details: {e}")
99
  print(f"Error type: {type(e)}")
 
 
100
  raise gr.Error(f"이미지 생성 실패: {e}")
101
 
102
  def run_multi_image_logic(prompt: str, images: List[str], progress=gr.Progress()) -> str:
@@ -133,17 +143,25 @@ def run_multi_image_logic(prompt: str, images: List[str], progress=gr.Progress()
133
 
134
  progress(0.8, desc="🖼️ 마무리 중...")
135
 
136
- # Handle the output
137
  if output:
138
- # If output is a FileOutput object, get the URL
139
  if hasattr(output, 'url'):
140
- image_url = output.url()
 
 
141
  elif isinstance(output, str):
142
  image_url = output
 
143
  elif isinstance(output, list) and len(output) > 0:
144
- image_url = output[0]
 
 
 
 
 
145
  else:
146
- raise ValueError("Unexpected output format from Replicate")
147
 
148
  # Download the image from URL
149
  response = requests.get(image_url)
@@ -160,6 +178,8 @@ def run_multi_image_logic(prompt: str, images: List[str], progress=gr.Progress()
160
 
161
  except Exception as e:
162
  print(f"Multi-image error details: {e}")
 
 
163
  raise gr.Error(f"이미지 생성 실패: {e}")
164
 
165
  # --- Gradio App UI ---
 
69
 
70
  progress(0.8, desc="🖼️ 마무리 중...")
71
 
72
+ # Handle the output - output is already a URL string or FileObject
73
  if output:
74
+ # Check if output has a url attribute (FileObject)
75
  if hasattr(output, 'url'):
76
+ # If url is a method, call it; if it's a property, just access it
77
+ image_url = output.url() if callable(output.url) else output.url
78
+ # If output is already a string URL
79
  elif isinstance(output, str):
80
  image_url = output
81
+ # If output is a list of URLs
82
  elif isinstance(output, list) and len(output) > 0:
83
+ # Check first item in list
84
+ first_item = output[0]
85
+ if hasattr(first_item, 'url'):
86
+ image_url = first_item.url() if callable(first_item.url) else first_item.url
87
+ else:
88
+ image_url = first_item
89
  else:
90
+ raise ValueError(f"Unexpected output format from Replicate: {type(output)}")
91
 
92
  # Download the image from URL
93
  response = requests.get(image_url)
 
105
  except Exception as e:
106
  print(f"Error details: {e}")
107
  print(f"Error type: {type(e)}")
108
+ print(f"Output value: {output if 'output' in locals() else 'Not set'}")
109
+ print(f"Output type: {type(output) if 'output' in locals() else 'Not set'}")
110
  raise gr.Error(f"이미지 생성 실패: {e}")
111
 
112
  def run_multi_image_logic(prompt: str, images: List[str], progress=gr.Progress()) -> str:
 
143
 
144
  progress(0.8, desc="🖼️ 마무리 중...")
145
 
146
+ # Handle the output - output is already a URL string or FileObject
147
  if output:
148
+ # Check if output has a url attribute (FileObject)
149
  if hasattr(output, 'url'):
150
+ # If url is a method, call it; if it's a property, just access it
151
+ image_url = output.url() if callable(output.url) else output.url
152
+ # If output is already a string URL
153
  elif isinstance(output, str):
154
  image_url = output
155
+ # If output is a list of URLs
156
  elif isinstance(output, list) and len(output) > 0:
157
+ # Check first item in list
158
+ first_item = output[0]
159
+ if hasattr(first_item, 'url'):
160
+ image_url = first_item.url() if callable(first_item.url) else first_item.url
161
+ else:
162
+ image_url = first_item
163
  else:
164
+ raise ValueError(f"Unexpected output format from Replicate: {type(output)}")
165
 
166
  # Download the image from URL
167
  response = requests.get(image_url)
 
178
 
179
  except Exception as e:
180
  print(f"Multi-image error details: {e}")
181
+ print(f"Output value: {output if 'output' in locals() else 'Not set'}")
182
+ print(f"Output type: {type(output) if 'output' in locals() else 'Not set'}")
183
  raise gr.Error(f"이미지 생성 실패: {e}")
184
 
185
  # --- Gradio App UI ---