Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import pandas as pd | |
| import cloudinary | |
| import cloudinary.uploader | |
| from datetime import datetime | |
| import uuid | |
| from io import BytesIO | |
| from PIL import Image | |
| # Load Excel codes | |
| df = pd.read_excel("RMSheet1.xlsx") | |
| CODES = df["Row Labels"].dropna().astype(str).tolist() | |
| # Cloudinary config (change this to your keys) | |
| cloudinary.config( | |
| cloud_name="diih3ajsp", # β Replace | |
| api_key="174463748698396", # β Replace | |
| api_secret="Py_vc_NwOSmdmMKUL5M2n2h_TNk" # β Replace | |
| ) | |
| def upload_to_cloudinary(img, code): | |
| if img is None or code is None: | |
| return "β Upload image and select code" | |
| # Generate filename | |
| filename = f"{code}_{datetime.now().strftime('%Y%m%d_%H%M%S')}_{uuid.uuid4().hex[:6]}.jpg" | |
| # Save image to buffer | |
| buffer = BytesIO() | |
| img.save(buffer, format="JPEG") | |
| buffer.seek(0) | |
| # Upload to Cloudinary | |
| result = cloudinary.uploader.upload(buffer, public_id=filename, folder="multiuser_uploads", resource_type="image") | |
| return f"β Uploaded: [View Image]({result['secure_url']})" | |
| # Gradio UI | |
| gr.Interface( | |
| fn=upload_to_cloudinary, | |
| inputs=[ | |
| gr.Image(type="pil", label="Capture or Upload Image"), | |
| gr.Dropdown(choices=CODES, label="Select from column: #code") | |
| ], | |
| outputs="markdown", | |
| title="Cloudinary Image Logger" | |
| ).launch() | |
| # Gradio UI with searchable dropdown | |
| gr.Interface( | |
| fn=upload_to_cloudinary, | |
| inputs=[ | |
| gr.Image(type="pil", label="Capture or Upload Image"), | |
| gr.Dropdown(choices=CODES, label="Select from column: #code", filterable=True) | |
| ], | |
| outputs="markdown", | |
| title="Cloudinary Image Logger" | |
| ).launch() | |