JasonTPhillipsJr commited on
Commit
5c91758
1 Parent(s): 52dffea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -11
app.py CHANGED
@@ -1,20 +1,34 @@
1
  import streamlit as st
 
2
  from transformers import pipeline
3
  from PIL import Image
4
 
5
- pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
6
 
7
- st.title("Hot Dog? Or Not?")
 
8
 
9
- file_name = st.file_uploader("Upload a hot dog candidate image")
10
 
11
- if file_name is not None:
12
- col1, col2 = st.columns(2)
 
 
 
13
 
14
- image = Image.open(file_name)
15
- col1.image(image, use_column_width=True)
16
- predictions = pipeline(image)
 
 
 
 
 
 
17
 
18
- col2.header("Probabilities")
19
- for p in predictions:
20
- col2.subheader(f"{ p['label'] }: { round(p['score'] * 100, 1)}%")
 
 
 
 
1
  import streamlit as st
2
+ import spacy
3
  from transformers import pipeline
4
  from PIL import Image
5
 
6
+ nlp = spacy.load("en_core_web_sm")
7
 
8
+ st.title("SpaGAN Demo")
9
+ st.write("Enter a text, and the system will highlight the geo-entities within it.")
10
 
11
+ user_input = st.text_area("Input Text", height=200)
12
 
13
+ # Process the text when the button is clicked
14
+ if st.button("Highlight Geo-Entities"):
15
+ if user_input.strip():
16
+ # Process the text using spaCy
17
+ doc = nlp(user_input)
18
 
19
+ # Highlight geo-entities
20
+ highlighted_text = user_input
21
+ for ent in reversed(doc.ents):
22
+ if ent.label_ in ["GPE", "LOC"]: # GPE = Geopolitical Entity, LOC = Location
23
+ highlighted_text = (
24
+ highlighted_text[:ent.start_char] +
25
+ f"**:green[{ent.text}]**" +
26
+ highlighted_text[ent.end_char:]
27
+ )
28
 
29
+ # Display the highlighted text
30
+ st.markdown(highlighted_text)
31
+ else:
32
+ st.error("Please enter some text.")
33
+
34
+ st.write("Note: The model identifies and highlights geo-entities