devskale
commited on
Commit
•
760d3ff
1
Parent(s):
ad8818b
gitignore
Browse files- .gitignore +1 -0
- gradio_test.py +0 -47
.gitignore
CHANGED
@@ -2,3 +2,4 @@
|
|
2 |
.gradio
|
3 |
__pycache__
|
4 |
**/.DS_Store
|
|
|
|
2 |
.gradio
|
3 |
__pycache__
|
4 |
**/.DS_Store
|
5 |
+
test_*.py
|
gradio_test.py
DELETED
@@ -1,47 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from PIL import Image
|
3 |
-
import os
|
4 |
-
import io
|
5 |
-
|
6 |
-
def get_file_info(file):
|
7 |
-
"""Get file info from the uploaded file."""
|
8 |
-
if file is None:
|
9 |
-
return "No file uploaded."
|
10 |
-
|
11 |
-
# Extract original filename
|
12 |
-
original_name = os.path.splitext(os.path.basename(file.name))[0]
|
13 |
-
|
14 |
-
# Open the image file
|
15 |
-
image = Image.open(file.name)
|
16 |
-
|
17 |
-
# Get image dimensions
|
18 |
-
width, height = image.size
|
19 |
-
|
20 |
-
# Calculate file size
|
21 |
-
size_bytes = os.path.getsize(file.name)
|
22 |
-
size_kb = size_bytes / 1024
|
23 |
-
|
24 |
-
return f"""<div style="text-align: left; padding: 5px;">
|
25 |
-
<p>Original Name: {original_name}</p>
|
26 |
-
<p>Size: {width}x{height}px ({size_kb:.1f} KB)</p>
|
27 |
-
</div>"""
|
28 |
-
|
29 |
-
with gr.Blocks(title="Gradio File Info Test") as interface:
|
30 |
-
gr.Markdown("# 🖼️ Gradio File Info Test 🛠️")
|
31 |
-
gr.Markdown("📤 Upload an image to test file info handling.")
|
32 |
-
|
33 |
-
with gr.Row():
|
34 |
-
with gr.Column(scale=1):
|
35 |
-
# Input column
|
36 |
-
input_file = gr.File(label="Upload Image")
|
37 |
-
input_info = gr.HTML(label="Input Image Information") # For showing input image info
|
38 |
-
|
39 |
-
# Update image info when file changes
|
40 |
-
input_file.change(
|
41 |
-
fn=get_file_info,
|
42 |
-
inputs=[input_file],
|
43 |
-
outputs=[input_info]
|
44 |
-
)
|
45 |
-
|
46 |
-
if __name__ == "__main__":
|
47 |
-
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|