Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,7 +11,6 @@ import logging
|
|
| 11 |
from datetime import datetime
|
| 12 |
import hashlib
|
| 13 |
import shutil
|
| 14 |
-
import requests
|
| 15 |
import gradio as gr
|
| 16 |
from google import genai
|
| 17 |
from google.genai import types
|
|
@@ -36,26 +35,6 @@ logger = logging.getLogger(__name__)
|
|
| 36 |
LOGS_DIR = "generation_logs"
|
| 37 |
os.makedirs(LOGS_DIR, exist_ok=True)
|
| 38 |
|
| 39 |
-
def get_location_from_ip(ip):
|
| 40 |
-
"""Get approximate location from IP address"""
|
| 41 |
-
if ip == "unknown" or ip.startswith("127.") or ip.startswith("192.168."):
|
| 42 |
-
return {"country": "unknown", "city": "unknown"}
|
| 43 |
-
|
| 44 |
-
try:
|
| 45 |
-
response = requests.get(f"https://ipapi.co/{ip}/json/", timeout=2)
|
| 46 |
-
data = response.json()
|
| 47 |
-
return {
|
| 48 |
-
"ip": ip,
|
| 49 |
-
"country": data.get("country_name", "unknown"),
|
| 50 |
-
"city": data.get("city", "unknown"),
|
| 51 |
-
"region": data.get("region", "unknown"),
|
| 52 |
-
"latitude": data.get("latitude"),
|
| 53 |
-
"longitude": data.get("longitude")
|
| 54 |
-
}
|
| 55 |
-
except Exception as e:
|
| 56 |
-
logger.error(f"Geolocation failed: {e}")
|
| 57 |
-
return {"country": "unknown", "city": "unknown"}
|
| 58 |
-
|
| 59 |
def save_generation_log(prompt, images_dict, metadata=None, request_info=None):
|
| 60 |
"""Save generation logs with images and user info"""
|
| 61 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
@@ -70,7 +49,6 @@ def save_generation_log(prompt, images_dict, metadata=None, request_info=None):
|
|
| 70 |
"session_id": session_id,
|
| 71 |
"prompt": prompt,
|
| 72 |
"client_ip": request_info.get("ip") if request_info else None,
|
| 73 |
-
"location": request_info.get("location") if request_info else None,
|
| 74 |
"user_agent": request_info.get("user_agent") if request_info else None,
|
| 75 |
"metadata": metadata or {}
|
| 76 |
}
|
|
@@ -360,14 +338,14 @@ def edit_3d_model(edit_prompt: str, transparent_image_path: str) -> str:
|
|
| 360 |
def generate_3d_ui(prompt, request: gr.Request, progress=gr.Progress()):
|
| 361 |
"""UI wrapper with progress updates"""
|
| 362 |
|
|
|
|
| 363 |
client_ip = request.headers.get("x-forwarded-for", "").split(",")[0].strip()
|
| 364 |
if not client_ip:
|
| 365 |
client_ip = request.client.host if request else "unknown"
|
| 366 |
-
location = get_location_from_ip(client_ip)
|
| 367 |
user_agent = request.headers.get("user-agent", "unknown") if request else "unknown"
|
| 368 |
|
| 369 |
logger.info(f"=== NEW GENERATION REQUEST ===")
|
| 370 |
-
logger.info(f"IP: {client_ip}
|
| 371 |
logger.info(f"Prompt: {prompt}")
|
| 372 |
|
| 373 |
if not client:
|
|
@@ -476,7 +454,6 @@ def generate_3d_ui(prompt, request: gr.Request, progress=gr.Progress()):
|
|
| 476 |
}
|
| 477 |
request_info = {
|
| 478 |
"ip": client_ip,
|
| 479 |
-
"location": location,
|
| 480 |
"user_agent": user_agent
|
| 481 |
}
|
| 482 |
save_generation_log(prompt, images_dict, metadata, request_info)
|
|
@@ -500,12 +477,13 @@ def edit_3d_ui(edit_prompt, current_image, edit_count, request: gr.Request, prog
|
|
| 500 |
"""UI wrapper for editing"""
|
| 501 |
|
| 502 |
# Get client info
|
| 503 |
-
client_ip = request.
|
| 504 |
-
|
|
|
|
| 505 |
user_agent = request.headers.get("user-agent", "unknown") if request else "unknown"
|
| 506 |
|
| 507 |
logger.info(f"=== EDIT REQUEST #{edit_count + 1} ===")
|
| 508 |
-
logger.info(f"IP: {client_ip}
|
| 509 |
logger.info(f"Edit: {edit_prompt}")
|
| 510 |
|
| 511 |
if current_image is None:
|
|
@@ -591,7 +569,6 @@ def edit_3d_ui(edit_prompt, current_image, edit_count, request: gr.Request, prog
|
|
| 591 |
}
|
| 592 |
request_info = {
|
| 593 |
"ip": client_ip,
|
| 594 |
-
"location": location,
|
| 595 |
"user_agent": user_agent
|
| 596 |
}
|
| 597 |
save_generation_log(edit_prompt, images_dict, metadata, request_info)
|
|
@@ -653,7 +630,7 @@ with gr.Blocks() as main_ui:
|
|
| 653 |
|
| 654 |
⏱️ *Generation takes 1-2 minutes. First run may take longer as the model warms up.*
|
| 655 |
|
| 656 |
-
📍 *Note: IP addresses
|
| 657 |
""")
|
| 658 |
|
| 659 |
gr.Markdown("## 1️⃣ Generate Initial 3D Model")
|
|
|
|
| 11 |
from datetime import datetime
|
| 12 |
import hashlib
|
| 13 |
import shutil
|
|
|
|
| 14 |
import gradio as gr
|
| 15 |
from google import genai
|
| 16 |
from google.genai import types
|
|
|
|
| 35 |
LOGS_DIR = "generation_logs"
|
| 36 |
os.makedirs(LOGS_DIR, exist_ok=True)
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
def save_generation_log(prompt, images_dict, metadata=None, request_info=None):
|
| 39 |
"""Save generation logs with images and user info"""
|
| 40 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
|
|
| 49 |
"session_id": session_id,
|
| 50 |
"prompt": prompt,
|
| 51 |
"client_ip": request_info.get("ip") if request_info else None,
|
|
|
|
| 52 |
"user_agent": request_info.get("user_agent") if request_info else None,
|
| 53 |
"metadata": metadata or {}
|
| 54 |
}
|
|
|
|
| 338 |
def generate_3d_ui(prompt, request: gr.Request, progress=gr.Progress()):
|
| 339 |
"""UI wrapper with progress updates"""
|
| 340 |
|
| 341 |
+
# Get client info
|
| 342 |
client_ip = request.headers.get("x-forwarded-for", "").split(",")[0].strip()
|
| 343 |
if not client_ip:
|
| 344 |
client_ip = request.client.host if request else "unknown"
|
|
|
|
| 345 |
user_agent = request.headers.get("user-agent", "unknown") if request else "unknown"
|
| 346 |
|
| 347 |
logger.info(f"=== NEW GENERATION REQUEST ===")
|
| 348 |
+
logger.info(f"IP: {client_ip}")
|
| 349 |
logger.info(f"Prompt: {prompt}")
|
| 350 |
|
| 351 |
if not client:
|
|
|
|
| 454 |
}
|
| 455 |
request_info = {
|
| 456 |
"ip": client_ip,
|
|
|
|
| 457 |
"user_agent": user_agent
|
| 458 |
}
|
| 459 |
save_generation_log(prompt, images_dict, metadata, request_info)
|
|
|
|
| 477 |
"""UI wrapper for editing"""
|
| 478 |
|
| 479 |
# Get client info
|
| 480 |
+
client_ip = request.headers.get("x-forwarded-for", "").split(",")[0].strip()
|
| 481 |
+
if not client_ip:
|
| 482 |
+
client_ip = request.client.host if request else "unknown"
|
| 483 |
user_agent = request.headers.get("user-agent", "unknown") if request else "unknown"
|
| 484 |
|
| 485 |
logger.info(f"=== EDIT REQUEST #{edit_count + 1} ===")
|
| 486 |
+
logger.info(f"IP: {client_ip}")
|
| 487 |
logger.info(f"Edit: {edit_prompt}")
|
| 488 |
|
| 489 |
if current_image is None:
|
|
|
|
| 569 |
}
|
| 570 |
request_info = {
|
| 571 |
"ip": client_ip,
|
|
|
|
| 572 |
"user_agent": user_agent
|
| 573 |
}
|
| 574 |
save_generation_log(edit_prompt, images_dict, metadata, request_info)
|
|
|
|
| 630 |
|
| 631 |
⏱️ *Generation takes 1-2 minutes. First run may take longer as the model warms up.*
|
| 632 |
|
| 633 |
+
📍 *Note: IP addresses are logged for analytics.*
|
| 634 |
""")
|
| 635 |
|
| 636 |
gr.Markdown("## 1️⃣ Generate Initial 3D Model")
|