samyak152002 commited on
Commit
5bf24c4
·
verified ·
1 Parent(s): 9d67ccc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -24
app.py CHANGED
@@ -1,32 +1,25 @@
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
31
  if __name__ == "__main__":
32
- demo.launch()
 
1
  import gradio as gr
2
  from span_marker import SpanMarkerModel
3
 
4
+ # Download the model from the Hugging Face Hub
5
+ model = SpanMarkerModel.from_pretrained("tomaarsen/span-marker-bert-base-acronyms")
6
+
7
+ # Define the function for prediction
8
+ def predict_acronyms(text):
 
9
  if text:
10
+ output = model.predict(text)
11
+ return output
12
+ return {"error": "Please provide valid text"}
 
 
13
 
14
+ # Create the Gradio interface
15
+ interface = gr.Interface(
16
+ fn=predict_acronyms,
17
+ inputs=gr.Textbox(label="Enter some text:", lines=5, placeholder="Type here..."),
18
+ outputs=gr.JSON(label="Predicted Output"),
19
+ title="Acronym Detection with Span Marker",
20
+ description="This application detects acronyms in the given text using the SpanMarker model."
 
 
 
 
21
  )
22
 
23
+ # Launch the Gradio app
24
  if __name__ == "__main__":
25
+ interface.launch()