openfree commited on
Commit
a19af11
·
verified ·
1 Parent(s): 6c2404b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -17
app.py CHANGED
@@ -3,12 +3,12 @@ from datasets import load_dataset
3
  from rapidfuzz import process, fuzz
4
 
5
  # ──────────────────────────────────────────────────────────
6
- # 1) 데이터셋 로드 (스트리밍) ─ 메모리에 메타만 저장
7
  # ──────────────────────────────────────────────────────────
8
  ds = load_dataset(
9
  "nyuuzyou/clker-svg",
10
  split="train",
11
- streaming=True, # .jsonl.zst → 자동 스트리밍 해제
12
  )
13
  records = []
14
  for ex in ds:
@@ -23,16 +23,16 @@ for ex in ds:
23
  )
24
 
25
  # ──────────────────────────────────────────────────────────
26
- # 2) 검색 함수
27
  # ──────────────────────────────────────────────────────────
28
  def search_svg(query: str, top_k: int):
29
  if not query.strip():
30
- return "⚠️ 검색어를 입력하세요.", None
31
 
32
- # choices: index(int) ➜ title+tags 한 줄 문자열
33
  choices = {i: f"{r['title']} {r['tags']}" for i, r in enumerate(records)}
34
 
35
- # Rapidfuzz: (choice_text, score, key) 반환
36
  matched = process.extract(
37
  query,
38
  choices,
@@ -44,23 +44,23 @@ def search_svg(query: str, top_k: int):
44
  html_start = '<div class="gallery-grid">'
45
  html_end = '</div>'
46
 
47
- for _, score, idx in matched: # idx 실제 list 인덱스
48
  r = records[idx]
49
  svg_html = (
50
  '<div class="gallery-item">'
51
  f'<div class="svg-container">{r["svg"]}</div>'
52
  f'<div class="item-details">'
53
  f'<h3>{r["title"]}</h3>'
54
- f'<div class="score">매칭 점수: {score}</div>'
55
  f'<div class="tags">{r["tags"]}</div>'
56
- f'<a href="{r["url"]}" target="_blank" class="download-link">원본 다운로드</a>'
57
  f'</div>'
58
  '</div>'
59
  )
60
  html_snippets.append(svg_html)
61
 
62
  if not html_snippets:
63
- return "검색 결과가 없습니다.", None
64
 
65
  return "", html_start + ''.join(html_snippets) + html_end
66
 
@@ -69,8 +69,8 @@ def search_svg(query: str, top_k: int):
69
  # ──────────────────────────────────────────────────────────
70
  TITLE = "🔍 Clker SVG"
71
  DESCRIPTION = """
72
- 애플리케이션은 "nyuuzyou/clker-svg" 데이터셋을 사용하여 퍼블릭 도메인 SVG 클립아트를 빠르게 검색할 있습니다.
73
- 퍼지 매칭을 통해 제목과 태그에서 유사한 항목을 찾아 시각적 갤러리로 표시합니다.
74
  """
75
  DISCORD_BADGE = """<p style="text-align:center; margin-top: -10px;"><a href="https://discord.gg/openfreeai" target="_blank"> <img src="https://img.shields.io/static/v1?label=Discord&message=Openfree%20AI&color=%230000ff&labelColor=%23800080&logo=discord&logoColor=white&style=for-the-badge" alt="badge"></a></p>"""
76
 
@@ -151,8 +151,8 @@ with gr.Blocks(title=TITLE, css=CSS) as demo:
151
  with gr.Row():
152
  with gr.Column(scale=4):
153
  query_box = gr.Textbox(
154
- label="검색어",
155
- placeholder="예: cat, tree, house, computer, flower...",
156
  show_label=True
157
  )
158
  with gr.Column(scale=1):
@@ -161,11 +161,11 @@ with gr.Blocks(title=TITLE, css=CSS) as demo:
161
  maximum=50,
162
  value=12,
163
  step=3,
164
- label="결과 개수"
165
  )
166
 
167
  with gr.Row():
168
- search_button = gr.Button("검색", variant="primary")
169
 
170
  warning_md = gr.Markdown()
171
  output_html = gr.HTML()
@@ -183,4 +183,4 @@ with gr.Blocks(title=TITLE, css=CSS) as demo:
183
  )
184
 
185
  if __name__ == "__main__":
186
- demo.launch()
 
3
  from rapidfuzz import process, fuzz
4
 
5
  # ──────────────────────────────────────────────────────────
6
+ # 1) Load dataset (streaming) ─ only metadata kept in memory
7
  # ──────────────────────────────────────────────────────────
8
  ds = load_dataset(
9
  "nyuuzyou/clker-svg",
10
  split="train",
11
+ streaming=True, # .jsonl.zst → streamed automatically
12
  )
13
  records = []
14
  for ex in ds:
 
23
  )
24
 
25
  # ──────────────────────────────────────────────────────────
26
+ # 2) Search function
27
  # ──────────────────────────────────────────────────────────
28
  def search_svg(query: str, top_k: int):
29
  if not query.strip():
30
+ return "⚠️ Please enter a search term.", None
31
 
32
+ # choices: index(int) ➜ single-line title+tags string
33
  choices = {i: f"{r['title']} {r['tags']}" for i, r in enumerate(records)}
34
 
35
+ # Rapidfuzz: returns (choice_text, score, key)
36
  matched = process.extract(
37
  query,
38
  choices,
 
44
  html_start = '<div class="gallery-grid">'
45
  html_end = '</div>'
46
 
47
+ for _, score, idx in matched: # idx is actual list index
48
  r = records[idx]
49
  svg_html = (
50
  '<div class="gallery-item">'
51
  f'<div class="svg-container">{r["svg"]}</div>'
52
  f'<div class="item-details">'
53
  f'<h3>{r["title"]}</h3>'
54
+ f'<div class="score">Match score: {score}</div>'
55
  f'<div class="tags">{r["tags"]}</div>'
56
+ f'<a href="{r["url"]}" target="_blank" class="download-link">Download original</a>'
57
  f'</div>'
58
  '</div>'
59
  )
60
  html_snippets.append(svg_html)
61
 
62
  if not html_snippets:
63
+ return "No results found.", None
64
 
65
  return "", html_start + ''.join(html_snippets) + html_end
66
 
 
69
  # ──────────────────────────────────────────────────────────
70
  TITLE = "🔍 Clker SVG"
71
  DESCRIPTION = """
72
+ This application lets you quickly search public-domain SVG clip art using the “nyuuzyou/clker-svg” dataset.
73
+ It finds similar items in titles and tags through fuzzy matching and shows them in a visual gallery.
74
  """
75
  DISCORD_BADGE = """<p style="text-align:center; margin-top: -10px;"><a href="https://discord.gg/openfreeai" target="_blank"> <img src="https://img.shields.io/static/v1?label=Discord&message=Openfree%20AI&color=%230000ff&labelColor=%23800080&logo=discord&logoColor=white&style=for-the-badge" alt="badge"></a></p>"""
76
 
 
151
  with gr.Row():
152
  with gr.Column(scale=4):
153
  query_box = gr.Textbox(
154
+ label="Search term",
155
+ placeholder="e.g. cat, tree, house, computer, flower...",
156
  show_label=True
157
  )
158
  with gr.Column(scale=1):
 
161
  maximum=50,
162
  value=12,
163
  step=3,
164
+ label="Number of results"
165
  )
166
 
167
  with gr.Row():
168
+ search_button = gr.Button("Search", variant="primary")
169
 
170
  warning_md = gr.Markdown()
171
  output_html = gr.HTML()
 
183
  )
184
 
185
  if __name__ == "__main__":
186
+ demo.launch()