geyik1 commited on
Commit
7abd3d4
·
verified ·
1 Parent(s): 70f2409

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -116
app.py DELETED
@@ -1,116 +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, seed=0, guidance_scale=7.5, num_inference_steps=20):
27
- try:
28
- print(f"Generating 3D icon with prompt: {prompt}")
29
-
30
- # Use the original goofyai/3d_render_style_xl model via gr.load
31
- try:
32
- # Try loading the model directly
33
- model = gr.load("goofyai/3d_render_style_xl", src="models")
34
- result = model(prompt)
35
- return result
36
- except Exception as e:
37
- print(f"Error with gr.load: {str(e)}")
38
-
39
- # Fallback: Create a simple colored rectangle as placeholder
40
- from PIL import Image, ImageDraw, ImageFont
41
- import random
42
-
43
- # Create a 512x512 image with random color
44
- colors = [(255, 87, 51), (255, 165, 0), (50, 205, 50), (30, 144, 255), (138, 43, 226)]
45
- bg_color = random.choice(colors)
46
-
47
- image = Image.new('RGB', (512, 512), color=bg_color)
48
- draw = ImageDraw.Draw(image)
49
-
50
- # Add text
51
- try:
52
- # Try to use a font
53
- font = ImageFont.truetype("/System/Library/Fonts/Arial.ttf", 36)
54
- except:
55
- font = ImageFont.load_default()
56
-
57
- # Draw prompt text in center
58
- bbox = draw.textbbox((0, 0), prompt, font=font)
59
- text_width = bbox[2] - bbox[0]
60
- text_height = bbox[3] - bbox[1]
61
- x = (512 - text_width) // 2
62
- y = (512 - text_height) // 2
63
-
64
- draw.text((x, y), prompt, fill=(255, 255, 255), font=font)
65
-
66
- # Add "3D Game Icon" label
67
- label = "3D Game Icon"
68
- try:
69
- label_font = ImageFont.truetype("/System/Library/Fonts/Arial.ttf", 24)
70
- except:
71
- label_font = ImageFont.load_default()
72
-
73
- draw.text((20, 20), label, fill=(255, 255, 255), font=label_font)
74
-
75
- return image
76
-
77
- except Exception as e:
78
- print(f"Error generating icon: {str(e)}")
79
- # Return a simple error image
80
- from PIL import Image, ImageDraw
81
-
82
- image = Image.new('RGB', (512, 512), color='lightgray')
83
- draw = ImageDraw.Draw(image)
84
- draw.text((200, 250), "Error", fill=(255, 0, 0))
85
- return image
86
-
87
- # Create Gradio interface
88
- def create_interface():
89
- interface = gr.Interface(
90
- fn=generate_3d_icon,
91
- inputs=[
92
- gr.Textbox(label="Prompt", placeholder="Describe your game icon", value="galatasaray"),
93
- gr.Slider(minimum=0, maximum=1000, value=0, step=1, label="Seed"),
94
- gr.Slider(minimum=1.0, maximum=20.0, value=7.5, step=0.5, label="Guidance Scale"),
95
- gr.Slider(minimum=10, maximum=50, value=20, step=1, label="Inference Steps")
96
- ],
97
- outputs=gr.Image(type="pil", label="Generated Game Icon"),
98
- title="3D Game Icon Generator",
99
- description="Generate 3D-style game icons using AI"
100
- )
101
-
102
- return interface
103
-
104
- # Launch the interface
105
- if __name__ == "__main__":
106
- try:
107
- interface = create_interface()
108
- print("Launching interface...")
109
- interface.launch(
110
- share=False,
111
- server_name="0.0.0.0",
112
- server_port=7860,
113
- show_error=True
114
- )
115
- except Exception as e:
116
- print(f"Error launching interface: {str(e)}")