therayz1 commited on
Commit
5c07633
·
verified ·
1 Parent(s): 2ba96a0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -37
app.py CHANGED
@@ -1,41 +1,25 @@
 
1
  import gradio as gr
2
- import stylecloud
3
- from PIL import Image
4
- import os
5
- import PIL.Image
6
 
7
- #fonksiyon tanımla
8
- # FontAwesome icon sınıflarını unicode karakterlere eşleyen sözlük
9
- icon_map = {
10
- "fas fa-car": "\uf1b9",
11
- "fas fa-star-and-crescent": "\uf699",
12
- "fas fa-trophy": "\uf091",
13
- "fas fa-heart": "\uf004"
14
- }
15
 
16
- def create_stylecloud(file, language, icon):
17
- output_file = 'stylecloud.png'
18
-
19
- # İkon değerini FontAwesome sınıf adından unicode karaktere dönüştür
20
- icon_unicode = icon_map.get(icon, "\uf1b9") # Varsayılan olarak "fas fa-car" ikonu
21
-
22
- stylecloud.gen_stylecloud(
23
- text=file,
24
- icon_name=icon_unicode,
25
- size=500,
26
- output_name=output_file,
27
- )
28
- return output_file
29
 
30
- with gr.Blocks() as demo:
31
- gr.Markdown('Kelime Bulutu Oluşturucu')
32
- with gr.Row():
33
- file_input = gr.File(label='Metin dosyasını yükle', type='binary')
34
- language = gr.Radio(choices=['TR', 'En'], label='Dil Seçimi', value='TR')
35
- icon = gr.Dropdown(choices=["fas fa-car", "fas fa-star-and-crescent", "fas fa-trophy", "fas fa-heart"], label='İkon seçimi', value="fas fa-car")
36
- output_file = gr.File(label='Kelime Bulutunu indir')
37
- create_button = gr.Button('Oluştur')
38
-
39
- create_button.click(fn=lambda: create_stylecloud(file_input=file_input, language=language, icon=icon), inputs=[file_input, language, icon], outputs=output_file)
40
-
41
- demo.launch()
 
1
+ # Step 2: Import libraries
2
  import gradio as gr
3
+ from wordcloud import WordCloud
4
+ import matplotlib.pyplot as plt
 
 
5
 
6
+ # Step 3: Define the word cloud generator function
7
+ def generate_word_cloud(text):
8
+ wordcloud = WordCloud(width=800, height=400, background_color='white').generate(text)
9
+ plt.figure(figsize=(10, 5))
10
+ plt.imshow(wordcloud, interpolation='bilinear')
11
+ plt.axis('off')
12
+ plt.savefig("wordcloud.png")
13
+ return "wordcloud.png"
14
 
15
+ # Step 4: Set up the Gradio interface
16
+ iface = gr.Interface(
17
+ fn=generate_word_cloud,
18
+ inputs=gr.components.Textbox(lines=10, placeholder="Enter text here..."),
19
+ outputs="image",
20
+ title="Word Cloud Generator",
21
+ description="Generate a word cloud from the input text"
22
+ )
 
 
 
 
 
23
 
24
+ # Step 5: Launch the interface in Colab
25
+ iface.launch(share=True)