Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
import os
|
4 |
+
import sys
|
5 |
+
from huggingface_hub import login
|
6 |
+
|
7 |
+
# Force CPU usage if needed
|
8 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
9 |
+
print(f"Using device: {device}")
|
10 |
+
|
11 |
+
# More details about the environment
|
12 |
+
print(f"Gradio version: {gr.__version__}")
|
13 |
+
print(f"Python version: {sys.version}")
|
14 |
+
|
15 |
+
# Hugging Face API token'ı - önce environment variable olarak ara,
|
16 |
+
# sonra Hugging Face Secrets sisteminde ara
|
17 |
+
hf_token = os.environ.get("HUGGINGFACE_TOKEN")
|
18 |
+
if hf_token:
|
19 |
+
print("Found HUGGINGFACE_TOKEN in environment variables")
|
20 |
+
# Token ile giriş yap
|
21 |
+
login(token=hf_token)
|
22 |
+
print("Logged in with Hugging Face token")
|
23 |
+
else:
|
24 |
+
print("HUGGINGFACE_TOKEN not found in environment variables")
|
25 |
+
# Hugging Face Spaces bu değişkeni otomatik olarak yükleyecek
|
26 |
+
# eğer Spaces UI üzerinden secret olarak eklediyseniz
|
27 |
+
|
28 |
+
def load_model():
|
29 |
+
try:
|
30 |
+
print("Attempting to load 3D render style model...")
|
31 |
+
|
32 |
+
# Gradio 5.29.1 sürümü için doğru format:
|
33 |
+
# gr.load() fonksiyonu için 'src' parametresi belirtilmeli
|
34 |
+
try:
|
35 |
+
print("Trying to load from 'models' source...")
|
36 |
+
interface = gr.load(
|
37 |
+
name="goofyai/3d_render_style_xl",
|
38 |
+
src="models"
|
39 |
+
)
|
40 |
+
return interface
|
41 |
+
except Exception as e:
|
42 |
+
print(f"Error loading from 'models': {str(e)}")
|
43 |
+
|
44 |
+
# Hugging Face kaynağını deneyelim
|
45 |
+
try:
|
46 |
+
print("Trying to load from 'huggingface' source...")
|
47 |
+
interface = gr.load(
|
48 |
+
name="goofyai/3d_render_style_xl",
|
49 |
+
src="huggingface"
|
50 |
+
)
|
51 |
+
return interface
|
52 |
+
except Exception as e:
|
53 |
+
print(f"Error loading from 'huggingface': {str(e)}")
|
54 |
+
|
55 |
+
# Space kaynağını deneyelim
|
56 |
+
print("Trying to load from 'spaces' source...")
|
57 |
+
try:
|
58 |
+
interface = gr.load(
|
59 |
+
name="goofyai/3d_render_style_xl",
|
60 |
+
src="spaces"
|
61 |
+
)
|
62 |
+
return interface
|
63 |
+
except Exception as e:
|
64 |
+
print(f"Error loading from 'spaces': {str(e)}")
|
65 |
+
|
66 |
+
# Son çare: Interface.load() deneyelim
|
67 |
+
print("Trying legacy Interface.load()...")
|
68 |
+
try:
|
69 |
+
interface = gr.Interface.load(
|
70 |
+
"models/goofyai/3d_render_style_xl"
|
71 |
+
)
|
72 |
+
return interface
|
73 |
+
except Exception as e:
|
74 |
+
print(f"Error with Interface.load(): {str(e)}")
|
75 |
+
|
76 |
+
# En son çare: doğrudan 3D model oluşturma yaklaşımı
|
77 |
+
print("Attempting to create a basic model interface...")
|
78 |
+
|
79 |
+
def generate_3d_render(prompt):
|
80 |
+
# Burada gerçek model çağrısı olmadan basit bir arayüz dönüyoruz
|
81 |
+
# Asıl amacımız arayüzün çalışmasını sağlamak
|
82 |
+
return "Model yüklenemedi. Lütfen HuggingFace izinlerinizi kontrol edin."
|
83 |
+
|
84 |
+
# Basit bir Gradio arayüzü oluştur
|
85 |
+
interface = gr.Interface(
|
86 |
+
fn=generate_3d_render,
|
87 |
+
inputs=gr.Textbox(label="Prompt", placeholder="3D render description"),
|
88 |
+
outputs=gr.Textbox(label="Result"),
|
89 |
+
title="3D Render Style XL",
|
90 |
+
description="Enter a prompt to generate a 3D render"
|
91 |
+
)
|
92 |
+
|
93 |
+
return interface
|
94 |
+
|
95 |
+
except Exception as e:
|
96 |
+
print(f"Error loading model: {str(e)}")
|
97 |
+
return None
|
98 |
+
|
99 |
+
# Create the interface
|
100 |
+
try:
|
101 |
+
interface = load_model()
|
102 |
+
if interface:
|
103 |
+
print("Model loaded successfully, launching interface...")
|
104 |
+
interface.launch(
|
105 |
+
share=False,
|
106 |
+
server_name="0.0.0.0",
|
107 |
+
server_port=7860,
|
108 |
+
show_error=True
|
109 |
+
)
|
110 |
+
else:
|
111 |
+
print("Failed to load the interface")
|
112 |
+
except Exception as e:
|
113 |
+
print(f"Error launching interface: {str(e)}")
|