Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,30 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import pipeline
|
3 |
from span_marker import SpanMarkerModel
|
4 |
|
5 |
# Define the function
|
6 |
-
def function(
|
7 |
# Load the pre-trained model from Hugging Face
|
8 |
model = SpanMarkerModel.from_pretrained("tomaarsen/span-marker-bert-base-acronyms")
|
9 |
|
10 |
# Ensure the input is valid
|
11 |
-
if
|
12 |
-
# Run inference on the input
|
13 |
-
out = model.predict(
|
14 |
return out
|
15 |
else:
|
16 |
return "Please provide valid text input."
|
17 |
|
18 |
# Set up the Gradio interface
|
19 |
-
demo = gr.
|
20 |
fn=function,
|
21 |
-
|
22 |
-
|
23 |
-
title="Abbreviation Detector"
|
|
|
|
|
|
|
|
|
|
|
24 |
)
|
25 |
|
26 |
# Launch the app
|
|
|
1 |
import gradio as gr
|
|
|
2 |
from span_marker import SpanMarkerModel
|
3 |
|
4 |
# Define the function
|
5 |
+
def function(text):
|
6 |
# Load the pre-trained model from Hugging Face
|
7 |
model = SpanMarkerModel.from_pretrained("tomaarsen/span-marker-bert-base-acronyms")
|
8 |
|
9 |
# Ensure the input is valid
|
10 |
+
if text:
|
11 |
+
# Run inference on the input text
|
12 |
+
out = model.predict([text]) # Wrap the text in a list as the model expects a list of strings
|
13 |
return out
|
14 |
else:
|
15 |
return "Please provide valid text input."
|
16 |
|
17 |
# Set up the Gradio interface
|
18 |
+
demo = gr.Interface(
|
19 |
fn=function,
|
20 |
+
inputs=gr.Textbox(lines=5, placeholder="Enter your text here...", label="Input Text"),
|
21 |
+
outputs="json",
|
22 |
+
title="Abbreviation Detector",
|
23 |
+
examples=[
|
24 |
+
"NASA is an abbreviation for National Aeronautics and Space Administration.",
|
25 |
+
"AI stands for Artificial Intelligence.",
|
26 |
+
"What does HTTP mean?"
|
27 |
+
]
|
28 |
)
|
29 |
|
30 |
# Launch the app
|