Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -15,6 +15,13 @@ import torch.nn.functional as F
|
|
15 |
device = torch.device('cpu')
|
16 |
torch.set_num_threads(4) # Optimize CPU performance
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
# Style presets
|
19 |
STYLE_PRESETS = {
|
20 |
"Sketch": {"line_thickness": 1.0, "contrast": 1.2, "brightness": 1.0},
|
@@ -62,8 +69,8 @@ class HistoryManager:
|
|
62 |
return self.history[-1]["settings"]
|
63 |
return None
|
64 |
|
65 |
-
# Initialize history manager
|
66 |
-
history_manager = HistoryManager()
|
67 |
|
68 |
norm_layer = nn.InstanceNorm2d
|
69 |
|
@@ -401,10 +408,14 @@ with gr.Blocks(css=custom_css) as iface:
|
|
401 |
]
|
402 |
)
|
403 |
|
404 |
-
# Launch the interface
|
405 |
iface.launch(
|
406 |
server_name="0.0.0.0",
|
407 |
server_port=7860,
|
408 |
share=False,
|
409 |
-
debug=False
|
|
|
|
|
|
|
|
|
410 |
)
|
|
|
15 |
device = torch.device('cpu')
|
16 |
torch.set_num_threads(4) # Optimize CPU performance
|
17 |
|
18 |
+
# Optimize memory usage
|
19 |
+
torch.backends.cudnn.benchmark = False
|
20 |
+
torch.backends.cudnn.deterministic = True
|
21 |
+
|
22 |
+
# Reduce memory usage for history
|
23 |
+
MAX_HISTORY_ENTRIES = 5
|
24 |
+
|
25 |
# Style presets
|
26 |
STYLE_PRESETS = {
|
27 |
"Sketch": {"line_thickness": 1.0, "contrast": 1.2, "brightness": 1.0},
|
|
|
69 |
return self.history[-1]["settings"]
|
70 |
return None
|
71 |
|
72 |
+
# Initialize history manager with reduced entries
|
73 |
+
history_manager = HistoryManager(max_entries=MAX_HISTORY_ENTRIES)
|
74 |
|
75 |
norm_layer = nn.InstanceNorm2d
|
76 |
|
|
|
408 |
]
|
409 |
)
|
410 |
|
411 |
+
# Launch the interface with optimized settings
|
412 |
iface.launch(
|
413 |
server_name="0.0.0.0",
|
414 |
server_port=7860,
|
415 |
share=False,
|
416 |
+
debug=False,
|
417 |
+
show_error=True,
|
418 |
+
max_threads=4,
|
419 |
+
ssr=False, # Disable SSR to prevent Node.js issues
|
420 |
+
cache_examples=False, # Disable example caching to save memory
|
421 |
)
|