Spaces:
Runtime error
Runtime error
[email protected]
commited on
Commit
•
47a68c5
1
Parent(s):
47f3322
why's this taking so long
Browse files- README.md +1 -21
- language_models_project/app.py +13 -3
- language_models_project/main.py +8 -4
README.md
CHANGED
@@ -13,24 +13,4 @@ pinned: false
|
|
13 |
# image2textapp
|
14 |
demo of 🤗 spaces deployment of a streamlit python app
|
15 |
|
16 |
-
|
17 |
-
Installation instructions
|
18 |
-
|
19 |
-
```docker compose run dev-environment```
|
20 |
-
|
21 |
-
Procedure used:
|
22 |
-
|
23 |
-
Reasoned that it would make the most amount of sense to be able to modify the
|
24 |
-
source code while the container is still running to allow for iterative
|
25 |
-
debugging in the environment in which it is being deployed. To avoid writing
|
26 |
-
back to the system, a readonly option was provided to the filesystem.
|
27 |
-
|
28 |
-
Docker compose was used to provide a separation of concerns, and to move testing
|
29 |
-
logic outside of the container that is to be deployed. This decouples the logic
|
30 |
-
of the tests from the application logic. I have familiarity with docker compose
|
31 |
-
and am happy to work with it again.
|
32 |
-
|
33 |
-
A bare-metal python Dockerfile base image was used to provide a stable python
|
34 |
-
deployment version. This version will be targeted in the poetry files, and
|
35 |
-
packages necessary will be installed into the system python with the appropriate
|
36 |
-
poetry arguments.
|
|
|
13 |
# image2textapp
|
14 |
demo of 🤗 spaces deployment of a streamlit python app
|
15 |
|
16 |
+
deployed at https://huggingface.co/spaces/NativeVex/large-language-models
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
language_models_project/app.py
CHANGED
@@ -10,16 +10,26 @@ st.title("Easy OCR - Extract Text from Images")
|
|
10 |
#subtitle
|
11 |
st.markdown("## Optical Character Recognition - Using `easyocr`, `streamlit` - hosted on 🤗 Spaces")
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
input_sentences = st.text_area("Sentences", value="", height=200)
|
14 |
|
15 |
data = input_sentences.split('\n')
|
16 |
|
17 |
#if st.button("Classify"):
|
18 |
for i in data:
|
19 |
-
|
20 |
-
|
|
|
21 |
confidence = j['score']
|
22 |
-
st.write(f"{i} :: Classification - {
|
23 |
|
24 |
|
25 |
st.markdown("Link to the app - [image-to-text-app on 🤗 Spaces](https://huggingface.co/spaces/Amrrs/image-to-text-app)")
|
|
|
10 |
#subtitle
|
11 |
st.markdown("## Optical Character Recognition - Using `easyocr`, `streamlit` - hosted on 🤗 Spaces")
|
12 |
|
13 |
+
model_name = st.selectbox(
|
14 |
+
'Select a pre-trained model',
|
15 |
+
[
|
16 |
+
'finiteautomata/bertweet-base-sentiment-analysis',
|
17 |
+
'ahmedrachid/FinancialBERT-Sentiment-Analysis',
|
18 |
+
'finiteautomata/beto-sentiment-analysis'
|
19 |
+
],
|
20 |
+
)
|
21 |
+
|
22 |
input_sentences = st.text_area("Sentences", value="", height=200)
|
23 |
|
24 |
data = input_sentences.split('\n')
|
25 |
|
26 |
#if st.button("Classify"):
|
27 |
for i in data:
|
28 |
+
st.write(i)
|
29 |
+
j = classify(model_name.strip(), i)[0]
|
30 |
+
sentiment = j['label']
|
31 |
confidence = j['score']
|
32 |
+
st.write(f"{i} :: Classification - {sentiment} with confidence {confidence}")
|
33 |
|
34 |
|
35 |
st.markdown("Link to the app - [image-to-text-app on 🤗 Spaces](https://huggingface.co/spaces/Amrrs/image-to-text-app)")
|
language_models_project/main.py
CHANGED
@@ -1,8 +1,12 @@
|
|
1 |
from transformers import pipeline
|
2 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
3 |
|
4 |
-
def classify(*args, **kwargs):
|
5 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
6 |
-
model = AutoModelForSequenceClassification.from_pretrained(
|
7 |
-
sentiment_pipeline = pipeline(
|
|
|
|
|
|
|
|
|
8 |
return sentiment_pipeline(*args, **kwargs)
|
|
|
1 |
from transformers import pipeline
|
2 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
3 |
|
4 |
+
def classify(model_string: str, *args, **kwargs):
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained(model_string)
|
6 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_string)
|
7 |
+
sentiment_pipeline = pipeline(
|
8 |
+
"sentiment-analysis",
|
9 |
+
model=model,
|
10 |
+
tokenizer=tokenizer
|
11 |
+
)
|
12 |
return sentiment_pipeline(*args, **kwargs)
|