File size: 4,448 Bytes
8dad306
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import gradio as gr
import torch
import os
import sys
from huggingface_hub import login

# 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")
    # Token ile giriş yap
    login(token=hf_token)
    print("Logged in with Hugging Face token")
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:
        print("Attempting to load 3D render style model...")
        
        # Gradio 5.29.1 sürümü için doğru format:
        # gr.load() fonksiyonu için 'src' parametresi belirtilmeli
        try:
            print("Trying to load from 'models' source...")
            interface = gr.load(
                name="goofyai/3d_render_style_xl",
                src="models"
            )
            return interface
        except Exception as e:
            print(f"Error loading from 'models': {str(e)}")
            
            # Hugging Face kaynağını deneyelim
            try:
                print("Trying to load from 'huggingface' source...")
                interface = gr.load(
                    name="goofyai/3d_render_style_xl",
                    src="huggingface"
                )
                return interface
            except Exception as e:
                print(f"Error loading from 'huggingface': {str(e)}")
                
                # Space kaynağını deneyelim
                print("Trying to load from 'spaces' source...")
                try:
                    interface = gr.load(
                        name="goofyai/3d_render_style_xl",
                        src="spaces"
                    )
                    return interface
                except Exception as e:
                    print(f"Error loading from 'spaces': {str(e)}")
                    
                    # Son çare: Interface.load() deneyelim
                    print("Trying legacy Interface.load()...")
                    try:
                        interface = gr.Interface.load(
                            "models/goofyai/3d_render_style_xl"
                        )
                        return interface
                    except Exception as e:
                        print(f"Error with Interface.load(): {str(e)}")
                        
                        # En son çare: doğrudan 3D model oluşturma yaklaşımı
                        print("Attempting to create a basic model interface...")
                        
                        def generate_3d_render(prompt):
                            # Burada gerçek model çağrısı olmadan basit bir arayüz dönüyoruz
                            # Asıl amacımız arayüzün çalışmasını sağlamak
                            return "Model yüklenemedi. Lütfen HuggingFace izinlerinizi kontrol edin."
                        
                        # Basit bir Gradio arayüzü oluştur
                        interface = gr.Interface(
                            fn=generate_3d_render,
                            inputs=gr.Textbox(label="Prompt", placeholder="3D render description"),
                            outputs=gr.Textbox(label="Result"),
                            title="3D Render Style XL",
                            description="Enter a prompt to generate a 3D render"
                        )
                        
                        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)}")