Download app.py from byikp/carp: direct link, hf CLI and curl.
- Browser
- Download file 1.63 kB
-
https://huggingface.co/spaces/byikp/carp/resolve/main/app.py
- Command line
-
hf download hf://spaces/byikp/carp/app.py
-
curl -L -o app.py https://huggingface.co/spaces/byikp/carp/resolve/main/app.py
1.63 kB
| import gradio as gr | |
| import sympy | |
| from graphviz import Digraph | |
| # Asal çarpanları bulan fonksiyon | |
| def asal_carpanlar(sayi): | |
| return sympy.factorint(sayi) | |
| # Çarpan ağacını oluşturmak için rekürsif fonksiyon | |
| def carpan_agaci(sayi): | |
| factors = sympy.factorint(sayi) | |
| if len(factors) == 1 and list(factors.values())[0] == 1: | |
| return str(sayi) | |
| else: | |
| factor = list(factors.keys())[0] | |
| return [sayi, carpan_agaci(factor), carpan_agaci(sayi // factor)] | |
| # Ağacı grafiksel olarak oluşturan fonksiyon | |
| def ciz_agac(agac, graph=None): | |
| if graph is None: | |
| graph = Digraph() | |
| if isinstance(agac, list): | |
| parent = str(agac[0]) | |
| left, right = agac[1], agac[2] | |
| for child in [left, right]: | |
| child_label = str(child[0]) if isinstance(child, list) else str(child) | |
| graph.edge(parent, child_label) | |
| if isinstance(child, list): | |
| ciz_agac(child, graph) | |
| return graph | |
| # Gradio arayüzü fonksiyonu | |
| def asal_carpan_gorseli(sayi): | |
| agac = carpan_agaci(int(sayi)) | |
| graph = ciz_agac(agac) | |
| graph.render("asal_carpan_agaci", format="png") | |
| return "asal_carpan_agaci.png" | |
| # Gradio arayüz tasarımı | |
| with gr.Blocks() as demo: | |
| gr.Markdown("### 🔢 Asal Çarpan Ağacı Hesaplama") | |
| with gr.Row(): | |
| sayi = gr.Number(label="Bir sayı girin", minimum=2, value=48) | |
| btn = gr.Button("Asal Çarpan Ağacını Oluştur 🌳") | |
| output_img = gr.Image(label="Asal Çarpan Ağacı Görseli", type="filepath") | |
| btn.click(asal_carpan_gorseli, inputs=sayi, outputs=output_img) | |
| demo.launch() | |