bowenchen118 commited on
Commit
f4ec98b
·
1 Parent(s): 130d8b3
Files changed (1) hide show
  1. app.py +24 -17
app.py CHANGED
@@ -1,27 +1,34 @@
1
  import gradio as gr
2
- import datetime
3
  import os
 
 
4
 
5
- # Ensure logs directory exists
6
- os.makedirs("logs", exist_ok=True)
7
 
8
- def log_user_data(inputs, outputs):
9
- # Create a log entry
10
- timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
11
- log_entry = f"{timestamp} | Input: {inputs} | Output: {outputs}\n"
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
- return outputs
 
 
 
 
 
 
 
 
 
 
18
 
19
- def process_input(user_input):
20
- response = f"Hello, {user_input}!"
21
- log_user_data(user_input, response)
22
- return response
 
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