byikp commited on
Commit
da9a147
·
verified ·
1 Parent(s): b1f027e

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +62 -11
README.md CHANGED
@@ -1,12 +1,63 @@
1
- ---
2
- title: Carpanagaci
3
- emoji: 🐠
4
- colorFrom: gray
5
- colorTo: gray
6
- sdk: gradio
7
- sdk_version: 5.22.0
8
- app_file: app.py
9
- pinned: false
10
- ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import matplotlib.pyplot as plt
3
+ import networkx as nx
4
+ import math
 
 
 
 
 
 
5
 
6
+ def draw_factorization(number):
7
+ try:
8
+ number = int(number)
9
+ if number <= 0:
10
+ return None, "Pozitif tam sayı giriniz"
11
+
12
+ # Basit çarpan bulma
13
+ def get_factors(n):
14
+ factors = []
15
+ while n % 2 == 0:
16
+ factors.append(2)
17
+ n = n // 2
18
+ for i in range(3, int(math.sqrt(n))+1, 2):
19
+ while n % i == 0:
20
+ factors.append(i)
21
+ n = n // i
22
+ if n > 2:
23
+ factors.append(n)
24
+ return factors
25
+
26
+ factors = get_factors(number)
27
+
28
+ # Graf oluştur
29
+ G = nx.Graph()
30
+ G.add_node(number, pos=(0,0))
31
+
32
+ angle = 0
33
+ angle_step = 360/len(factors)
34
+ radius = 1
35
+
36
+ for i, factor in enumerate(factors):
37
+ x = radius * math.cos(math.radians(angle))
38
+ y = radius * math.sin(math.radians(angle))
39
+ G.add_node(f"{factor}_{i}", pos=(x,y))
40
+ G.add_edge(number, f"{factor}_{i}")
41
+ angle += angle_step
42
+
43
+ pos = nx.get_node_attributes(G, 'pos')
44
+ plt.figure(figsize=(6,6))
45
+ nx.draw(G, pos, with_labels=True, node_size=1000, node_color="skyblue")
46
+ plt.savefig("factors.png", bbox_inches='tight')
47
+ plt.close()
48
+
49
+ return "factors.png", f"Çarpanlar: {factors}"
50
+
51
+ except:
52
+ return None, "Geçersiz giriş"
53
+
54
+ with gr.Blocks() as demo:
55
+ gr.Markdown("## Çarpan Ağacı Görselleştirme")
56
+ inp = gr.Number(label="Sayı", value=36)
57
+ btn = gr.Button("Oluştur")
58
+ out_img = gr.Image(label="Çarpan Ağacı")
59
+ out_text = gr.Textbox(label="Sonuç")
60
+
61
+ btn.click(draw_factorization, inputs=inp, outputs=[out_img, out_text])
62
+
63
+ demo.launch()