KAARIN commited on
Commit
2d514bb
1 Parent(s): 19dc3fe

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +86 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+
4
+ # In[1]:
5
+
6
+
7
+ import gradio as gr
8
+ import stylecloud
9
+ from PIL import Image
10
+ import os
11
+
12
+
13
+ # In[3]:
14
+
15
+
16
+ def create_stylecloud(file, text_input, language, icon):
17
+ # Dosya veya text inputtan gelen metni kullan
18
+ if file:
19
+ text = file.decode('utf-8')
20
+ elif text_input:
21
+ text = text_input
22
+ else:
23
+ return None # Eğer ikisi de yoksa None döner
24
+
25
+ output_file = 'stylecloud.png'
26
+ stylecloud.gen_stylecloud(
27
+ text=text,
28
+ icon_name=icon,
29
+ size=500,
30
+ output_name=output_file
31
+ )
32
+
33
+ image = Image.open(output_file)
34
+ image = image.resize((300, 300))
35
+ return image
36
+
37
+ with gr.Blocks() as demo:
38
+ gr.Markdown('Kelime Bulutu Oluşturucu')
39
+
40
+ with gr.Row():
41
+ input_choice = gr.Radio(choices=['Dosya Yükle', 'Metin Gir'], label='Girdi Seçimi', value='Dosya Yükle')
42
+
43
+ with gr.Row(visible=True) as file_input_row:
44
+ file_input = gr.File(label='Metin Dosyası Yükle', type='binary')
45
+
46
+ with gr.Row(visible=False) as text_input_row:
47
+ text_input = gr.Textbox(label='Metin Gir')
48
+
49
+ with gr.Row():
50
+ language = gr.Radio(choices=['TR', 'EN'], label='Dil Seçimi', value='TR')
51
+
52
+ with gr.Row():
53
+ icon = gr.Dropdown(choices=["fas fa-car", "fas fa-star-and-crescent", "fas fa-trophy", "fas fa-heart"],
54
+ label='İkon Seçimi', value='fas fa-star-and-crescent')
55
+
56
+ with gr.Row():
57
+ create_button = gr.Button('Oluştur')
58
+ output_image = gr.Image(label='Kelime Bulutu')
59
+
60
+ # butona basıldığında
61
+ create_button.click(
62
+ create_stylecloud,
63
+ inputs=[file_input, text_input, language, icon],
64
+ outputs=output_image
65
+ )
66
+
67
+ def update_input_visibility(choice):
68
+ if choice == 'Dosya Yükle':
69
+ return gr.update(visible=True), gr.update(visible=False)
70
+ else:
71
+ return gr.update(visible=False), gr.update(visible=True)
72
+
73
+ input_choice.change(
74
+ update_input_visibility,
75
+ inputs=[input_choice],
76
+ outputs=[file_input_row, text_input_row]
77
+ )
78
+
79
+ demo.launch(share=True)
80
+
81
+
82
+ # In[ ]:
83
+
84
+
85
+
86
+
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio == 4.36.1
2
+ stylecloud==0.5.2
3
+ PIL==9.4.0