Spaces:
Runtime error
Runtime error
init app
Browse files- README.md +4 -4
- main.py +58 -0
- requirements.txt +1 -0
README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
---
|
2 |
-
title: Text Classification
|
3 |
-
emoji:
|
4 |
colorFrom: purple
|
5 |
colorTo: yellow
|
6 |
sdk: streamlit
|
7 |
sdk_version: 1.9.0
|
8 |
-
app_file:
|
9 |
-
pinned:
|
10 |
license: mit
|
11 |
---
|
12 |
|
|
|
1 |
---
|
2 |
+
title: Optimum Text Classification
|
3 |
+
emoji: ⭐⭐⭐
|
4 |
colorFrom: purple
|
5 |
colorTo: yellow
|
6 |
sdk: streamlit
|
7 |
sdk_version: 1.9.0
|
8 |
+
app_file: main.py
|
9 |
+
pinned: true
|
10 |
license: mit
|
11 |
---
|
12 |
|
main.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""⭐ Text Classification with Optimum and ONNXRuntime
|
2 |
+
|
3 |
+
Author:
|
4 |
+
- @ChainYo - https://github.com/ChainYo
|
5 |
+
"""
|
6 |
+
|
7 |
+
import streamlit as st
|
8 |
+
|
9 |
+
from transformers import AutoTokenizer, AutoModel, pipeline
|
10 |
+
from optimum.onnxruntime import ORTModelForTextClassification
|
11 |
+
from optimum.pipelines import pipeline
|
12 |
+
|
13 |
+
|
14 |
+
MODEL_PATH = "ProsusAI/finbert"
|
15 |
+
|
16 |
+
st.set_page_config(page_title="Optimum Text Classification", page_icon="⭐")
|
17 |
+
st.title("🤗 Optimum Text Classification")
|
18 |
+
st.subheader("Classify financial text with 🤗 Optimum and ONNXRuntime")
|
19 |
+
st.markdown("""
|
20 |
+
[![GitHub](https://img.shields.io/badge/-%23121011.svg?style=for-the-badge&logo=github&logoColor=white)](https://github.com/ChainYo)
|
21 |
+
[![HuggingFace](https://img.shields.io/badge/-yellow.svg?style=for-the-badge&logo=data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/Pgo8IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDIwMDEwOTA0Ly9FTiIKICJodHRwOi8vd3d3LnczLm9yZy9UUi8yMDAxL1JFQy1TVkctMjAwMTA5MDQvRFREL3N2ZzEwLmR0ZCI+CjxzdmcgdmVyc2lvbj0iMS4wIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiB3aWR0aD0iMTc1LjAwMDAwMHB0IiBoZWlnaHQ9IjE3NS4wMDAwMDBwdCIgdmlld0JveD0iMCAwIDE3NS4wMDAwMDAgMTc1LjAwMDAwMCIKIHByZXNlcnZlQXNwZWN0UmF0aW89InhNaWRZTWlkIG1lZXQiPgoKPGcgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMC4wMDAwMDAsMTc1LjAwMDAwMCkgc2NhbGUoMC4xMDAwMDAsLTAuMTAwMDAwKSIKZmlsbD0iIzAwMDAwMCIgc3Ryb2tlPSJub25lIj4KPHBhdGggZD0iTTU2MyAxMjM2IGMtMjkgLTEzIC02MyAtNTkgLTYzIC04NiAwIC0yNiAzMyAtODAgNTIgLTg2IDE1IC00IDI2IDEKNDMgMjEgMjAgMjYgMjQgMjcgNTMgMTcgMjggLTkgMzMgLTggNDIgOCAxNyAzMiAxMSA2OSAtMTcgOTkgLTM0IDM3IC02OCA0NQotMTEwIDI3eiIvPgo8cGF0aCBkPSJNMTA2NCAxMjQwIGMtNTAgLTIwIC03NyAtODYgLTU0IC0xMzAgOSAtMTYgMTQgLTE3IDQyIC04IDI5IDEwIDMzIDkKNTUgLTE3IDIxIC0yNCAyNyAtMjYgNDggLTE3IDMxIDE0IDUxIDc2IDM2IDExNCAtMTcgNDYgLTg0IDc2IC0xMjcgNTh6Ii8+CjxwYXRoIGQ9Ik02MDAgODg4IGMwIC00OSAxNiAtOTggNTAgLTE1MSA4NSAtMTM0IDMyNSAtMTM0IDQxMCAwIDUxIDgwIDY5IDE4MwozMSAxODMgLTEwIDAgLTUwIC0xNSAtODcgLTMyIC02MCAtMjkgLTc5IC0zMyAtMTQ5IC0zMyAtNzAgMCAtODkgNCAtMTQ5IDMzCi0zNyAxNyAtNzcgMzIgLTg3IDMyIC0xNSAwIC0xOSAtNyAtMTkgLTMyeiIvPgo8L2c+Cjwvc3ZnPgo=)](https://huggingface.co/ChainYo)
|
22 |
+
[![LinkedIn](https://img.shields.io/badge/-%230077B5.svg?style=for-the-badge&logo=linkedin&logoColor=white)](https://www.linkedin.com/in/thomas-chaigneau-dev/)
|
23 |
+
[![Discord](https://img.shields.io/badge/Chainyo%233610-%237289DA.svg?style=for-the-badge&logo=discord&logoColor=white)](https://discord.gg/)
|
24 |
+
""")
|
25 |
+
|
26 |
+
if "tokenizer" not in st.session_state:
|
27 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
|
28 |
+
st.session_state["tokenizer"] = tokenizer
|
29 |
+
|
30 |
+
if "ort_model" not in st.session_state:
|
31 |
+
ort_model = ORTModelForTextClassification.from_pretrained(MODEL_PATH, from_transformers=True)
|
32 |
+
st.session_state["ort_model"] = ort_model
|
33 |
+
|
34 |
+
if "pt_model" not in st.session_state:
|
35 |
+
pt_model = AutoModel.from_pretrained(MODEL_PATH)
|
36 |
+
st.session_state["pt_model"] = pt_model
|
37 |
+
|
38 |
+
if "ort_pipeline" not in st.session_state:
|
39 |
+
ort_pipeline = pipeline(
|
40 |
+
"text-classification", tokenizer=st.session_state["tokenizer"], model=st.session_state["ort_model"]
|
41 |
+
)
|
42 |
+
st.session_state["ort_pipeline"] = ort_pipeline
|
43 |
+
|
44 |
+
if "pt_pipeline" not in st.session_state:
|
45 |
+
pt_pipeline = pipeline(
|
46 |
+
"text-classification", tokenizer=st.session_state["tokenizer"], model=st.session_state["pt_model"]
|
47 |
+
)
|
48 |
+
st.session_state["pt_pipeline"] = pt_pipeline
|
49 |
+
|
50 |
+
|
51 |
+
model_format = st.radio("Choose the model format", ("PyTorch", "ONNXRuntime"))
|
52 |
+
optimized = st.checkbox("Optimize the model for inference", value=False)
|
53 |
+
quantized = st.checkbox("Quantize the model", value=False)
|
54 |
+
|
55 |
+
if model_format == "PyTorch":
|
56 |
+
optimized.disabled = True
|
57 |
+
quantized.disabled = True
|
58 |
+
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
optimum[onnxruntime]==1.2.2
|