ojas121 commited on
Commit
ca48a37
·
verified ·
1 Parent(s): f0edbfa

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -0
app.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+
5
+ # Load NER model
6
+ @st.cache_resource
7
+ def load_ner_model():
8
+ return pipeline("ner", grouped_entities=True)
9
+
10
+
11
+ ner_model = load_ner_model()
12
+
13
+ # Set the title with custom style
14
+ st.markdown(
15
+ "<h1 style='text-align: center; color: #4CAF50;'>Named Entity Recognition </h1>",
16
+ unsafe_allow_html=True
17
+ )
18
+
19
+ # Set up text input with a description
20
+ st.write(
21
+ "<p style='text-align: center;'>Enter your text below for entity recognition.</p>",
22
+ unsafe_allow_html=True
23
+ )
24
+
25
+ # Center the input text area
26
+ text_input = st.text_area(
27
+ "Text Input",
28
+ placeholder="Type your text here...",
29
+ height=200
30
+ )
31
+
32
+ # Customize the button and center it
33
+ button_style = """
34
+ <style>
35
+ div.stButton > button {
36
+ width: 100%;
37
+ background-color: #4CAF50;
38
+ color: white;
39
+ font-size: large;
40
+ padding: 10px;
41
+ border-radius: 8px;
42
+ }
43
+ </style>
44
+ """
45
+ st.markdown(button_style, unsafe_allow_html=True)
46
+
47
+ # Button to trigger NER model
48
+ if st.button("Recognize Entities"):
49
+ if text_input:
50
+ with st.spinner("Processing..."):
51
+ entities = ner_model(text_input)
52
+
53
+ if entities:
54
+ st.subheader("Named Entities")
55
+
56
+ # Loop through entities and display with improved visibility
57
+ for entity in entities:
58
+ entity_html = f"""
59
+ <div style="background-color: #333333; border-radius: 8px; padding: 10px; margin: 5px 0;">
60
+ <strong style="color: #ff9800;">Entity:</strong> {entity['word']}
61
+ <br>
62
+ <strong style="color: #03a9f4;">Type:</strong> {entity['entity_group']}
63
+ <br>
64
+ <strong style="color: #8bc34a;">Confidence:</strong> {entity['score']:.2f}
65
+ </div>
66
+ """
67
+ st.markdown(entity_html, unsafe_allow_html=True)
68
+ else:
69
+ st.write("No named entities found in the text.")
70
+ else:
71
+ st.error("Please enter some text for entity recognition.")