Update app.py
Browse files
app.py
CHANGED
|
@@ -1,41 +1,25 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
import os
|
| 5 |
-
import PIL.Image
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
"
|
| 14 |
-
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
icon_name=icon_unicode,
|
| 25 |
-
size=500,
|
| 26 |
-
output_name=output_file,
|
| 27 |
-
)
|
| 28 |
-
return output_file
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|