Spaces:
Runtime error
Runtime error
Commit
·
f4ec98b
1
Parent(s):
130d8b3
Update
Browse files
app.py
CHANGED
|
@@ -1,27 +1,34 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import datetime
|
| 3 |
import os
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
os.makedirs("
|
| 7 |
|
| 8 |
-
def
|
| 9 |
-
#
|
| 10 |
-
timestamp = datetime.datetime.now().strftime("%Y
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
# Write to a log file
|
| 14 |
-
with open("logs/user_data.log", "a") as log_file:
|
| 15 |
-
log_file.write(log_entry)
|
| 16 |
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
| 23 |
|
| 24 |
-
demo = gr.Interface(fn=process_input, inputs="text", outputs="text")
|
| 25 |
demo.launch()
|
| 26 |
|
| 27 |
# import os
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import os
|
| 3 |
+
import datetime
|
| 4 |
+
from PIL import Image
|
| 5 |
|
| 6 |
+
# Create a directory for uploaded images
|
| 7 |
+
os.makedirs("uploaded_images", exist_ok=True)
|
| 8 |
|
| 9 |
+
def save_image(image):
|
| 10 |
+
# Generate a timestamped filename
|
| 11 |
+
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 12 |
+
file_path = f"uploaded_images/image_{timestamp}.png"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
# Save the image
|
| 15 |
+
image.save(file_path)
|
| 16 |
+
|
| 17 |
+
# Check if saved
|
| 18 |
+
print(f"Image saved to: {file_path} | Exists: {os.path.exists(file_path)}")
|
| 19 |
+
|
| 20 |
+
# Open image and print dims
|
| 21 |
+
img = Image.open(file_path)
|
| 22 |
+
print(f"Image dimensions: {img.size}")
|
| 23 |
+
|
| 24 |
+
return f"Image saved to: {file_path}"
|
| 25 |
|
| 26 |
+
demo = gr.Interface(
|
| 27 |
+
fn=save_image,
|
| 28 |
+
inputs=gr.Image(type="pil"), # Accepts PIL Image objects
|
| 29 |
+
outputs="text"
|
| 30 |
+
)
|
| 31 |
|
|
|
|
| 32 |
demo.launch()
|
| 33 |
|
| 34 |
# import os
|