Spaces:
Sleeping
Sleeping
fix: font
Browse files
app.py
CHANGED
|
@@ -1,10 +1,21 @@
|
|
| 1 |
import re
|
|
|
|
|
|
|
|
|
|
| 2 |
import jieba
|
| 3 |
from PIL import Image
|
| 4 |
from wordcloud import WordCloud
|
| 5 |
import gradio as gr
|
| 6 |
from typing import List
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
def tokenize_text(text:str) -> List:
|
| 10 |
"""
|
|
@@ -40,6 +51,7 @@ def generate_world_cloud(text:str) -> Image.Image:
|
|
| 40 |
segmented = tokenize_text(text)
|
| 41 |
|
| 42 |
wc = WordCloud(
|
|
|
|
| 43 |
width=800,
|
| 44 |
height=400,
|
| 45 |
background_color='white'
|
|
|
|
| 1 |
import re
|
| 2 |
+
import os
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
import jieba
|
| 6 |
from PIL import Image
|
| 7 |
from wordcloud import WordCloud
|
| 8 |
import gradio as gr
|
| 9 |
from typing import List
|
| 10 |
|
| 11 |
+
FONT_PATH = "NotoSansCJK-Regular.otf"
|
| 12 |
+
FONT_URL = "https://github.com/adobe-fonts/source-han-sans/raw/release/OTF/SimplifiedChinese/SourceHanSansSC-Regular.otf"
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
if not os.path.exists(FONT_PATH):
|
| 16 |
+
print("Downloading font...")
|
| 17 |
+
with open(FONT_PATH, "wb") as f:
|
| 18 |
+
f.write(requests.get(FONT_URL).content)
|
| 19 |
|
| 20 |
def tokenize_text(text:str) -> List:
|
| 21 |
"""
|
|
|
|
| 51 |
segmented = tokenize_text(text)
|
| 52 |
|
| 53 |
wc = WordCloud(
|
| 54 |
+
font_path=FONT_PATH,
|
| 55 |
width=800,
|
| 56 |
height=400,
|
| 57 |
background_color='white'
|