geyik1 commited on
Commit
010c290
·
verified ·
1 Parent(s): 21504cf

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -124
app.py DELETED
@@ -1,124 +0,0 @@
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
-
26
- def generate_3d_icon(prompt):
27
- try:
28
- print(f"Generating 3D icon with prompt: {prompt}")
29
-
30
- # Try different methods to load the actual model
31
- try:
32
- print("Trying to load goofyai/3d_render_style_xl...")
33
-
34
- # Method 1: Direct model loading
35
- model = gr.load("goofyai/3d_render_style_xl", src="models")
36
- result = model(prompt)
37
- print("Model loaded and generated successfully")
38
- return result
39
-
40
- except Exception as e1:
41
- print(f"Method 1 failed: {str(e1)}")
42
-
43
- try:
44
- # Method 2: Try spaces source
45
- print("Trying spaces source...")
46
- model = gr.load("goofyai/3d_render_style_xl", src="spaces")
47
- result = model(prompt)
48
- print("Spaces model loaded successfully")
49
- return result
50
-
51
- except Exception as e2:
52
- print(f"Method 2 failed: {str(e2)}")
53
-
54
- try:
55
- # Method 3: Try huggingface source
56
- print("Trying huggingface source...")
57
- model = gr.load("goofyai/3d_render_style_xl", src="huggingface")
58
- result = model(prompt)
59
- print("HuggingFace model loaded successfully")
60
- return result
61
-
62
- except Exception as e3:
63
- print(f"Method 3 failed: {str(e3)}")
64
-
65
- try:
66
- # Method 4: Try with Interface.load
67
- print("Trying Interface.load...")
68
- model = gr.Interface.load("models/goofyai/3d_render_style_xl")
69
- result = model(prompt)
70
- print("Interface.load successful")
71
- return result
72
-
73
- except Exception as e4:
74
- print(f"Method 4 failed: {str(e4)}")
75
-
76
- # Final fallback - create error message
77
- from PIL import Image, ImageDraw, ImageFont
78
-
79
- image = Image.new('RGB', (512, 512), color='red')
80
- draw = ImageDraw.Draw(image)
81
-
82
- error_text = "Model loading failed"
83
- draw.text((200, 250), error_text, fill=(255, 255, 255))
84
-
85
- print("All methods failed, returning error image")
86
- return image
87
-
88
- except Exception as e:
89
- print(f"General error: {str(e)}")
90
- # Return error image
91
- from PIL import Image, ImageDraw
92
-
93
- image = Image.new('RGB', (512, 512), color='gray')
94
- draw = ImageDraw.Draw(image)
95
- draw.text((200, 250), "Error", fill=(255, 0, 0))
96
- return image
97
-
98
- # Create Gradio interface
99
- def create_interface():
100
- interface = gr.Interface(
101
- fn=generate_3d_icon,
102
- inputs=[
103
- gr.Textbox(label="Prompt", placeholder="Describe your game icon", value="galatasaray")
104
- ],
105
- outputs=gr.Image(type="pil", label="Generated Game Icon"),
106
- title="3D Game Icon Generator",
107
- description="Generate 3D-style game icons using AI"
108
- )
109
-
110
- return interface
111
-
112
- # Launch the interface
113
- if __name__ == "__main__":
114
- try:
115
- interface = create_interface()
116
- print("Launching interface...")
117
- interface.launch(
118
- share=False,
119
- server_name="0.0.0.0",
120
- server_port=7860,
121
- show_error=True
122
- )
123
- except Exception as e:
124
- print(f"Error launching interface: {str(e)}")