Spaces:
Sleeping
Sleeping
Download app.py from unthinkablee/xraydent: direct link, hf CLI and curl.
- Browser
- Download file 3.97 kB
-
https://huggingface.co/spaces/unthinkablee/xraydent/resolve/main/app.py
- Command line
-
hf download hf://spaces/unthinkablee/xraydent/app.py
-
curl -L -o app.py https://huggingface.co/spaces/unthinkablee/xraydent/resolve/main/app.py
3.97 kB
| import zipfile | |
| import os | |
| # ZIP dosyasını çıkarma işlemi | |
| zip_path = "Oral-3d-main.zip" # ZIP dosyanızın adı | |
| extract_path = "." # Mevcut dizine çıkar | |
| if os.path.exists(zip_path): | |
| with zipfile.ZipFile(zip_path, 'r') as zip_ref: | |
| zip_ref.extractall(extract_path) | |
| print(f"{zip_path} başarıyla çıkarıldı.") | |
| else: | |
| print(f"{zip_path} bulunamadı.") | |
| import os | |
| import subprocess | |
| # nibabel yüklü değilse yükle | |
| try: | |
| import nibabel | |
| except ImportError: | |
| print("nibabel yükleniyor...") | |
| subprocess.check_call(["pip", "install", "nibabel"]) | |
| import gradio as gr | |
| import subprocess | |
| import os | |
| import tempfile | |
| from PIL import Image | |
| import numpy as np | |
| def run_oral3d(test_mode, data_root, device, train_n, val_n, save_n, d_start_n, g_lr, d_lr, mode, test_only, input_image): | |
| try: | |
| # Panoramik görüntüyü geçici bir dosyaya kaydetme | |
| if input_image is not None: | |
| print("Görüntü yüklendi.") | |
| # Eğer input_image numpy array ise PIL Image formatına dönüştür | |
| if isinstance(input_image, np.ndarray): | |
| input_image = Image.fromarray(input_image) | |
| with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as tmp_file: | |
| input_image.save(tmp_file.name) | |
| image_path = tmp_file.name | |
| print(f"Görüntü geçici olarak {image_path} konumuna kaydedildi.") | |
| else: | |
| image_path = None | |
| print("Görüntü yüklenmedi.") | |
| # Komut satırı argümanlarını oluşturma | |
| cmd = [ | |
| "python", "main.py", | |
| "--data_root", data_root, | |
| "--device", device, | |
| "--train_n", str(train_n), | |
| "--val_n", str(val_n), | |
| "--save_n", str(save_n), | |
| "--d_start_n", str(d_start_n), | |
| "--g_lr", str(g_lr), | |
| "--d_lr", str(d_lr), | |
| "--mode", mode | |
| ] | |
| if test_mode: | |
| cmd.append("--test_mode") | |
| if test_only: | |
| cmd.append("--test_only") | |
| if image_path: # Panoramik görüntü yolu varsa ekleyin | |
| cmd.extend(["--input_image", image_path]) | |
| print(f"Çalıştırılan komut: {' '.join(cmd)}") # Çalıştırılan komutu göster | |
| # Komutu çalıştırma ve çıktı alma | |
| result = subprocess.run(cmd, capture_output=True, text=True) | |
| print("Komut çıktısı:", result.stdout) # Komut çıktısını yazdır | |
| print("Komut hatası:", result.stderr) # Hata varsa yazdır | |
| return result.stdout if result.stdout else "Çıktı alınamadı veya hata oluştu." | |
| except Exception as e: | |
| print(f"Hata oluştu: {e}") | |
| return f"Hata oluştu: {e}" | |
| # Gradio arayüzü tanımlama | |
| iface = gr.Interface( | |
| fn=run_oral3d, | |
| inputs=[ | |
| gr.Checkbox(label="Test Mode"), | |
| gr.Textbox(label="Data Root", value="./data/mat"), | |
| gr.Textbox(label="Device", value="cpu"), | |
| gr.Slider(label="Training Epochs", minimum=1, maximum=100, step=1, value=20), | |
| gr.Slider(label="Validation Epochs", minimum=1, maximum=20, step=1, value=5), | |
| gr.Slider(label="Model Save Interval", minimum=1, maximum=100, step=1, value=20), | |
| gr.Slider(label="Discriminator Start Epoch", minimum=1, maximum=20, step=1, value=5), | |
| gr.Number(label="Generator Learning Rate", value=0.001), | |
| gr.Number(label="Discriminator Learning Rate", value=0.001), | |
| gr.Dropdown(label="Mode", choices=["train", "test"], value="test"), | |
| gr.Checkbox(label="Load Test Data Only"), | |
| gr.Image(label="Panoramik Görüntü Yükleyin") # Panoramik görüntü yükleme alanı | |
| ], | |
| outputs="text", | |
| title="Oral-3D Modeli", | |
| description="Oral-3D modelini eğitmek veya panoramik görüntüleri test etmek için gerekli ayarları yapın ve çalıştırın." | |
| ) | |
| iface.launch() | |