Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -99,8 +99,23 @@ model2 = Generator(3, 1, 3) # Initialize the model architecture
|
|
| 99 |
model2.load_state_dict(torch.load('model2.pth', map_location=torch.device('cpu')))
|
| 100 |
model2.eval() # Set the model to evaluation mode
|
| 101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
# 🖼️ Function to process the image and create line drawing
|
| 103 |
def predict(input_img, ver):
|
|
|
|
|
|
|
| 104 |
# Open the image and get its original size
|
| 105 |
original_img = Image.open(input_img)
|
| 106 |
original_size = original_img.size
|
|
|
|
| 99 |
model2.load_state_dict(torch.load('model2.pth', map_location=torch.device('cpu')))
|
| 100 |
model2.eval() # Set the model to evaluation mode
|
| 101 |
|
| 102 |
+
def download_image(url, save_path="temp_image.png"):
|
| 103 |
+
"""Download an image from a URL and save it locally."""
|
| 104 |
+
response = requests.get(url)
|
| 105 |
+
if response.status_code == 200:
|
| 106 |
+
with open(save_path, "wb") as f:
|
| 107 |
+
f.write(response.content)
|
| 108 |
+
return save_path
|
| 109 |
+
else:
|
| 110 |
+
raise Exception(f"Failed to download image: {response.status_code}")
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
|
| 115 |
# 🖼️ Function to process the image and create line drawing
|
| 116 |
def predict(input_img, ver):
|
| 117 |
+
if isinstance(input_img, str) and input_img.startswith("http"):
|
| 118 |
+
input_img = download_image(input_img)
|
| 119 |
# Open the image and get its original size
|
| 120 |
original_img = Image.open(input_img)
|
| 121 |
original_size = original_img.size
|