finished the predict function
Browse files- Pipfile +14 -0
- Pipfile.lock +0 -0
- app.py +44 -0
- requirements.txt +3 -0
Pipfile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[[source]]
|
| 2 |
+
url = "https://pypi.org/simple"
|
| 3 |
+
verify_ssl = true
|
| 4 |
+
name = "pypi"
|
| 5 |
+
|
| 6 |
+
[packages]
|
| 7 |
+
gradio = "*"
|
| 8 |
+
transformers = "*"
|
| 9 |
+
tensorflow = "*"
|
| 10 |
+
|
| 11 |
+
[dev-packages]
|
| 12 |
+
|
| 13 |
+
[requires]
|
| 14 |
+
python_version = "3.8"
|
Pipfile.lock
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
# loading the model
|
| 5 |
+
model_checkpoint = 'zinoubm/e-comerce-category-classification'
|
| 6 |
+
model = pipeline(
|
| 7 |
+
"text-classification", model=model_checkpoint,
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
def predict(input):
|
| 11 |
+
predictions = model(input)
|
| 12 |
+
predictions = [prediction['label'] for prediction in predictions]
|
| 13 |
+
return ' '.join(predictions)
|
| 14 |
+
|
| 15 |
+
# defining demo content
|
| 16 |
+
title = 'E-Commerce Category Prediction.'
|
| 17 |
+
|
| 18 |
+
description = '''
|
| 19 |
+
This is a classification model that predicts the category of an input.
|
| 20 |
+
We have 4 Categories, Electronics, Household, Books and Clothing & Accessories.
|
| 21 |
+
'''
|
| 22 |
+
|
| 23 |
+
article = '''
|
| 24 |
+
# How to use this interface
|
| 25 |
+
Using the interface is straight forward, just type some text that falls in one of these 4 categories: **Electronics**, **Household**, **Books** or **Clothing & Accessories**.
|
| 26 |
+
and then hit **Submit**. the results will be in the output cell. You can also try one of the provided examples.
|
| 27 |
+
'''
|
| 28 |
+
|
| 29 |
+
examples = [
|
| 30 |
+
['I want to sell a laptop'],
|
| 31 |
+
['This is a beatiful T-shirt'],
|
| 32 |
+
['Save 50% on detergent powder']
|
| 33 |
+
]
|
| 34 |
+
|
| 35 |
+
# launching the interface
|
| 36 |
+
gr.Interface(fn=predict,
|
| 37 |
+
inputs="text",
|
| 38 |
+
title=title,
|
| 39 |
+
description=description,
|
| 40 |
+
article=article,
|
| 41 |
+
outputs="text",
|
| 42 |
+
examples = examples,
|
| 43 |
+
theme='default',
|
| 44 |
+
).launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
transformers
|
| 3 |
+
tensorflow
|