Spaces:
Sleeping
Sleeping
import gradio as gr | |
import pandas as pd | |
from gliner import GLiNER | |
model = GLiNER.from_pretrained("knowledgator/gliner-multitask-large-v0.5") | |
def grouped(entities): | |
# Create a dictionary to store grouped entities | |
grouped_entities = {} | |
for entity in entities['entities']: | |
entity_type = entity['entity'] | |
# Use set to store unique elements for each entity type | |
if entity_type not in grouped_entities: | |
grouped_entities[entity_type] = set() | |
grouped_entities[entity_type].add(entity['word']) | |
# Convert sets back to lists (optional) | |
for entity_type, words in grouped_entities.items(): | |
grouped_entities[entity_type] = list(words) | |
df = pd.DataFrame(list(grouped_entities.items()), columns=['Label', 'Words']) | |
return df | |
def ner(text, labels): | |
labels = labels.split(',') | |
entities = {'text' : text, | |
'entities' : [ | |
{'entity': entity['label'], | |
'word': entity['text'], | |
'start': entity['start'], | |
'end': entity['end'], | |
'score': entity['score'], | |
} | |
for entity in model.predict_entities(text, labels) | |
] | |
} | |
dataframe = grouped(entities) | |
return entities,dataframe | |
demo = gr.Interface(fn=ner, | |
inputs=[gr.Textbox(placeholder="Enter sentence here..."), | |
gr.Textbox(placeholder="Enter labels here...")], | |
outputs=[gr.HighlightedText(), | |
gr.Dataframe()], | |
examples = [[''' Hurricane Ernesto knocked out power, downed trees and flooded parts of Bermuda on Saturday but the British island territory appeared to have escaped major injuries or property damage, officials said after an initial assessment. | |
Some 5.9 inches (150 mm) of rain had fallen and more was expected from the back end of the storm, Michelle Pitcher, director of the Bermuda Weather Service, said on the video. | |
The U.S. National Weather Service said the hurricane was tracking north-northeast. As of 5 p.m. EDT (2100 GMT), it had moved about 85 miles (135 km) past Bermuda, which lies some 600 miles (1,000 km) off the Carolina coast, and was expected to continue moving away on Saturday.''', | |
"person, name, location, measurements, date, event, direction, organization"], | |
['''One of the most thrilling films ever- special edition highly recommended | |
James Cameron is an extremely talented action director because not only does he know great action, but he always backs the action up with a great story and interesting characters. Aliens is his finest achievement, as far as I'm concerned. Of course, I should specify: Aliens Special Edition is his finest achievement. | |
In 1986 several scenes were cut to keep the movie's run-time reasonable but there was one scene that was incredibly foolish to leave out. The scene I refer to is near the beginning where Ripley learns that her daughter has died while she was away in 'hypersleep' for 57 years. "I promised her I'd be home for her 11th birthday," cries Ripley. This is a very moving scene that adds a great deal the character's depth and makes more sense to why she cares for a little girl named Newt later in the film. She's seeking penance through Newt with her love and determination to keep her alive at all costs. The theatrical edition obviously doesn't elude to any of this, and even cheapens the relationship between Ripley and Newt- just a little bit. James Cameron has said that all of his movies are love stories, and Aliens is a story of parental love. He has also said that the special edition is his intended (if not definitive) version of the film. For about five years or so the Special Edition was the only version of Aliens you could get on DVD. It should have stayed that way. | |
Aliens is a unique film experience: it's genuinely thrilling and exciting, unlike a lot of movies where people shoot the evil monsters and there's disgusting blood and rapid gunfire, and it's really meaningless. In Aliens' case, the aliens are very threatening and more than just target practice. We don't see any aliens for over an hour, but once we do, it's a huge payoff. By that time, we get to know some interesting characters: Hicks (Michael Beihn), a take-charge marine who also turns out to be sweet and sincere, Hudson (Bill Paxton), a braggart who turns out to be a coward and complains most of the time, Vasquez (Jeanette Goldstein), the iron-willed woman soldier who proves to be one of the bravest characters in the film, Bishop (Lance Henrikson), a robot that is very helpful for everyone's survival, Burke (Paul Rieser), the slimy company man who the audience loves to hate, and of course, the adorable little Newt (Carrie Henn), a girl who has survived unspeakable horror. Holding the whole film together is Ripley, played by Sigourney Weaver in her surprise-Oscar-nominated performance. I think the only reason why the audience cared for her in the first film is because she was the only person left and we wanted her to live. But for this film, James Cameron added so much to her. With all this investment in characters, we're really concerned for their well-being. We don't want those aliens to get them. Some die, and I'm always truly bummed out when it happens. | |
Filled with amazing performances and an abundance of thrills, Aliens is one of the greatest of any genre it attempts: whether it's action, sci-fi, horror, or even drama. I personally liked it better than the first film, but it's really like comparing apples and oranges. I prefer the special edition and don't see why anyone should view the other version instead.''', | |
"Character, place, actor name, director name, movie name, genre"]] | |
) | |
demo.launch() | |