Spaces:
Configuration error
Configuration error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
def sort_brands(brands):
|
| 4 |
+
"""
|
| 5 |
+
Accepts either:
|
| 6 |
+
- a comma-separated string
|
| 7 |
+
- one brand per line
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
if not brands:
|
| 11 |
+
return []
|
| 12 |
+
|
| 13 |
+
# Split by comma or newline
|
| 14 |
+
items = []
|
| 15 |
+
|
| 16 |
+
for line in brands.splitlines():
|
| 17 |
+
for item in line.split(","):
|
| 18 |
+
item = item.strip()
|
| 19 |
+
if item:
|
| 20 |
+
items.append(item)
|
| 21 |
+
|
| 22 |
+
# Remove duplicates (optional)
|
| 23 |
+
items = list(dict.fromkeys(items))
|
| 24 |
+
|
| 25 |
+
# Sort alphabetically (case-insensitive)
|
| 26 |
+
items = sorted(items, key=str.lower)
|
| 27 |
+
|
| 28 |
+
return items
|
| 29 |
+
|
| 30 |
+
demo = gr.Interface(
|
| 31 |
+
fn=sort_brands,
|
| 32 |
+
inputs=gr.Textbox(
|
| 33 |
+
label="Brands",
|
| 34 |
+
lines=10,
|
| 35 |
+
placeholder="Nike\nAdidas\nPuma"
|
| 36 |
+
),
|
| 37 |
+
outputs=gr.JSON(label="Sorted Brands"),
|
| 38 |
+
title="Brand Sort API",
|
| 39 |
+
description="Returns an alphabetically sorted list of brands."
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
demo.launch()
|