jethrovic commited on
Commit
789d284
·
1 Parent(s): 4dcb9ea

Create app.py

Browse files

added app.py file with code

Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ # Initialize the POS tagger
5
+ pos_tagger = pipeline(
6
+ model="vblagoje/bert-english-uncased-finetuned-pos",
7
+ aggregation_strategy="simple",
8
+ )
9
+
10
+ # Function to get color for each POS tag
11
+ def get_color(pos_tag):
12
+ colors = {
13
+ "PRON": "blue",
14
+ "VERB": "green",
15
+ "ADP": "red",
16
+ "PROPN": "orange",
17
+ # Add more POS tags and colors as needed
18
+ }
19
+ return colors.get(pos_tag, "grey") # Default color
20
+
21
+ # Streamlit app
22
+ st.title("Part-of-Speech Highlighter")
23
+
24
+ # Text input
25
+ text = st.text_area("Enter your text here:", "I am an artist and I live in Dublin")
26
+
27
+ # Process text and highlight POS
28
+ if text:
29
+ pos_result = pos_tagger(text)
30
+ highlighted_text = ""
31
+ for word_info in pos_result:
32
+ color = get_color(word_info["entity_group"])
33
+ highlighted_text += f'<span style="color:{color};">{word_info["word"]}</span> '
34
+
35
+ st.markdown(highlighted_text, unsafe_allow_html=True)