dnm3d / app.py
geyik1's picture
Upload app.py
c753085 verified
raw
history blame
2.37 kB
import gradio as gr
import torch
import os
import sys
# Force CPU usage if needed
device = "cuda" if torch.cuda.is_available() else "cpu"
print(f"Using device: {device}")
# More details about the environment
print(f"Gradio version: {gr.__version__}")
print(f"Python version: {sys.version}")
# Hugging Face API token'ı - önce environment variable olarak ara,
# sonra Hugging Face Secrets sisteminde ara
hf_token = os.environ.get("HUGGINGFACE_TOKEN")
if hf_token:
print("Found HUGGINGFACE_TOKEN in environment variables")
else:
print("HUGGINGFACE_TOKEN not found in environment variables")
# Hugging Face Spaces bu değişkeni otomatik olarak yükleyecek
# eğer Spaces UI üzerinden secret olarak eklediyseniz
def load_model():
try:
# Hugging Face modeline erişim için URL'yi düzelt
print("Attempting to load 3D render style model directly...")
try:
# Doğrudan model URL'si ile deneme
interface = gr.load("goofyai/3d_render_style_xl")
return interface
except Exception as e:
print(f"Error with direct load: {str(e)}")
# Alternatif: token ile deneyelim
if hf_token:
try:
from huggingface_hub import login
login(token=hf_token)
print("Logged in with token, trying to load model...")
interface = gr.load("goofyai/3d_render_style_xl")
return interface
except Exception as e:
print(f"Error loading with token: {str(e)}")
# Son çare: tam URL kullanarak deneyelim
print("Trying with full URL path...")
interface = gr.load("huggingface.co/goofyai/3d_render_style_xl")
return interface
except Exception as e:
print(f"Error loading model: {str(e)}")
return None
# Create the interface
try:
interface = load_model()
if interface:
print("Model loaded successfully, launching interface...")
interface.launch(
share=False,
server_name="0.0.0.0",
server_port=7860,
show_error=True
)
else:
print("Failed to load the interface")
except Exception as e:
print(f"Error launching interface: {str(e)}")