mcsqstudio commited on
Commit
8fbc9e4
·
verified ·
1 Parent(s): 4b2ae8f

Add Gradio classifier app (app.py, requirements.txt, README)

Browse files
Files changed (3) hide show
  1. README.md +35 -6
  2. app.py +90 -0
  3. requirements.txt +4 -0
README.md CHANGED
@@ -1,10 +1,39 @@
1
  ---
2
- title: Sitasector
3
- emoji: 🖼️
4
- colorFrom: yellow
5
- colorTo: red
6
- sdk: static
 
 
7
  pinned: false
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Sita Sector Classifier
3
+ emoji: 🌍
4
+ colorFrom: green
5
+ colorTo: green
6
+ sdk: gradio
7
+ sdk_version: 4.44.1
8
+ app_file: app.py
9
  pinned: false
10
  ---
11
 
12
+ # Sita Sector Classifier
13
+
14
+ Gradio web UI for the fine-tuned DistilBERT sector classifier built by MC Studio (Christine Matinde and Stacey Nduta) for the IBM x MC Studio Program.
15
+
16
+ ## What it does
17
+
18
+ Paste a company description and it predicts the most likely Sita Sector industry, with confidence.
19
+
20
+ ## Model
21
+
22
+ - Model: `mcsqstudio/africa-sector-classifier` (DistilBERT fine-tuned on 7 sectors)
23
+ - Dataset: [mcsqstudio/africa-startup-directory](https://huggingface.co/datasets/mcsqstudio/africa-startup-directory)
24
+
25
+ ## Sectors
26
+
27
+ | Code | Sector |
28
+ | ---- | ------ |
29
+ | ATX | Agritech |
30
+ | ETX | Edtech |
31
+ | HTX | Healthtech |
32
+ | FTX | Fintech |
33
+ | REC | Retail & E-commerce |
34
+ | ERG | Energy |
35
+ | MFG | Manufacturing |
36
+
37
+ ## Note
38
+
39
+ This Space activates the model lazily on first use. If it reports that the model is not ready, run `Sita_Sector_Model_v2_transformers.ipynb` in Colab to fine-tune and push the model, then click Classify again.
app.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import gradio as gr
3
+ from transformers import pipeline
4
+
5
+ MODEL_ID = "mcsqstudio/africa-sector-classifier"
6
+
7
+ SECTOR_NAMES = {
8
+ "ATX": "Agritech",
9
+ "ETX": "Edtech",
10
+ "HTX": "Healthtech",
11
+ "FTX": "Fintech",
12
+ "REC": "Retail & E-commerce",
13
+ "ERG": "Energy",
14
+ "MFG": "Manufacturing",
15
+ "XSC": "Cross-sector",
16
+ }
17
+
18
+ _pipe = None
19
+ _model_error = None
20
+
21
+
22
+ def get_pipe():
23
+ global _pipe, _model_error
24
+ if _pipe is None:
25
+ try:
26
+ _pipe = pipeline("text-classification", model=MODEL_ID, truncation=True)
27
+ _model_error = None
28
+ except Exception as exc:
29
+ _model_error = str(exc)
30
+ return _pipe
31
+
32
+
33
+ def classify(text):
34
+ if not text or not text.strip():
35
+ return pd.DataFrame(), "Please enter a company description."
36
+ pipe = get_pipe()
37
+ if pipe is None:
38
+ return pd.DataFrame(), (
39
+ "Model not ready yet. Run **Sita_Sector_Model_v2_transformers.ipynb** "
40
+ "in Colab to fine-tune and push `mcsqstudio/africa-sector-classifier` "
41
+ "to Hugging Face, then click Classify again.\n\n"
42
+ f"Detail: {_model_error}"
43
+ )
44
+ results = pipe(text.strip()[:2000])
45
+ rows = [
46
+ {
47
+ "Sector": r["label"],
48
+ "Sector name": SECTOR_NAMES.get(r["label"], ""),
49
+ "Confidence": round(r["score"], 4),
50
+ }
51
+ for r in results
52
+ ]
53
+ df = pd.DataFrame(rows)
54
+ top = rows[0]
55
+ headline = (
56
+ f"**{top['Sector']} - {SECTOR_NAMES.get(top['Sector'], '')}** "
57
+ f"({top['Confidence']:.1%} confidence)"
58
+ )
59
+ return df, headline
60
+
61
+
62
+ EXAMPLES = [
63
+ "Mobile payment platform enabling small businesses to accept card payments in Nairobi",
64
+ "Solar-powered microgrids bringing affordable electricity to rural communities in Uganda",
65
+ "Online marketplace connecting farmers directly to buyers and aggregating harvest data",
66
+ "AI tutoring app that personalizes math lessons for secondary school students in Nigeria",
67
+ "Telemedicine service offering remote consultations with licensed doctors in Kenya",
68
+ ]
69
+
70
+ with gr.Blocks(title="Sita Sector Classifier") as demo:
71
+ gr.Markdown(
72
+ "# Sita Sector Classifier\n"
73
+ "Classifies an African startup description into one of seven Sita Sector industries. "
74
+ "Fine-tuned DistilBERT on the "
75
+ "[Africa Startup Directory](https://huggingface.co/datasets/mcsqstudio/africa-startup-directory).\n\n"
76
+ "**Sectors:** ATX Agritech - ETX Edtech - HTX Healthtech - FTX Fintech - "
77
+ "REC Retail & E-commerce - ERG Energy - MFG Manufacturing"
78
+ )
79
+ txt = gr.Textbox(label="Company description", lines=4)
80
+ btn = gr.Button("Classify", variant="primary")
81
+ headline = gr.Markdown()
82
+ out = gr.Dataframe(
83
+ headers=["Sector", "Sector name", "Confidence"],
84
+ datatype=["str", "str", "number"],
85
+ interactive=False,
86
+ )
87
+ btn.click(classify, inputs=txt, outputs=[out, headline])
88
+ gr.Examples(examples=EXAMPLES, inputs=txt)
89
+
90
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio>=4.36
2
+ transformers>=4.44
3
+ torch>=2.1
4
+ pandas>=2.0