Lorden Games commited on
Commit
f8e7f35
·
verified ·
1 Parent(s): 80447c7

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -91
app.py DELETED
@@ -1,91 +0,0 @@
1
- import torch
2
- import gradio as gr
3
- from diffusers import ShapEPipeline
4
- from diffusers.utils import export_to_gif
5
- import os
6
- from huggingface_hub import HfApi, login
7
- import json
8
-
9
- # GPU kontrolü
10
- device = "cuda" if torch.cuda.is_available() else "cpu"
11
- print(f"Kullanılan cihaz: {device}")
12
-
13
- def validate_token(token):
14
- try:
15
- login(token=token)
16
- return True
17
- except Exception:
18
- return False
19
-
20
- def generate_3d_model(prompt, token, guidance_scale=15.0, num_steps=64, export_format="obj"):
21
- try:
22
- if not validate_token(token):
23
- return "Geçersiz Hugging Face token'ı", None, None
24
-
25
- print(f"Üretim başlıyor: {prompt}")
26
-
27
- # Model yükleme (token ile)
28
- pipe = ShapEPipeline.from_pretrained(
29
- "openai/shap-e",
30
- torch_dtype=torch.float32,
31
- use_auth_token=token
32
- ).to(device)
33
-
34
- # Çıktı klasörü kontrolü
35
- os.makedirs("outputs", exist_ok=True)
36
-
37
- # Dosya adı oluşturma
38
- safe_prompt = "".join(x for x in prompt if x.isalnum() or x in (" ", "-", "_"))
39
- base_filename = f"outputs/{safe_prompt}"
40
-
41
- # 3D model oluşturma
42
- images = pipe(
43
- prompt,
44
- guidance_scale=guidance_scale,
45
- num_inference_steps=num_steps,
46
- size=256,
47
- ).images
48
-
49
- # GIF kaydetme
50
- gif_path = export_to_gif(images, f"{base_filename}.gif")
51
-
52
- # 3D mesh oluşturma
53
- mesh = pipe(
54
- prompt,
55
- guidance_scale=guidance_scale,
56
- num_inference_steps=num_steps,
57
- output_type="mesh",
58
- ).meshes[0]
59
-
60
- # Mesh'i kaydetme
61
- output_path = f"{base_filename}.{export_format}"
62
- mesh.export(output_path)
63
-
64
- print(f"Üretim tamamlandı: {output_path}")
65
- return "Üretim başarılı!", gif_path, output_path
66
-
67
- except Exception as e:
68
- print(f"Hata oluştu: {str(e)}")
69
- return str(e), None, None
70
-
71
- # Gradio arayüzü
72
- interface = gr.Interface(
73
- fn=generate_3d_model,
74
- inputs=[
75
- gr.Textbox(label="3D Model için açıklama giriniz (İngilizce)"),
76
- gr.Textbox(label="Hugging Face Token", type="password"),
77
- gr.Slider(minimum=1, maximum=20, value=15, label="Guidance Scale"),
78
- gr.Slider(minimum=32, maximum=128, value=64, label="Adım Sayısı"),
79
- gr.Radio(["obj", "glb"], label="Export Formatı", value="obj")
80
- ],
81
- outputs=[
82
- gr.Textbox(label="Durum"),
83
- gr.Image(label="3D Önizleme (GIF)"),
84
- gr.File(label="3D Model Dosyası")
85
- ],
86
- title="DNM3D - 3D Model Üretici",
87
- description="Metin girişiyle 3D model oluşturun. Kullanmak için Hugging Face token'ınızı girmeniz gerekiyor."
88
- )
89
-
90
- if __name__ == "__main__":
91
- interface.launch()