sabarinathan commited on
Commit
d67f838
·
verified ·
1 Parent(s): 39bccfa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -1,4 +1,3 @@
1
-
2
  # -*- coding: utf-8 -*-
3
  """
4
  Created on Tue Sep 17 19:03:17 2024
@@ -53,7 +52,7 @@ class JapaneseNER():
53
  sample_encoding = self.tokenizer([
54
  "鈴木は4月の陽気の良い日に、鈴をつけて熊本県の阿蘇山に登った",
55
  "中国では、中国共産党による一党統治が続く",
56
- ], truncation=True,padding=True, # Ensure all sequences are of the same length
57
  max_length=512, return_tensors="pt")
58
 
59
  sample_encoding = {k: v.to(device) for k, v in sample_encoding.items()}
@@ -66,7 +65,7 @@ class JapaneseNER():
66
  print("Predicted labels:", predicted_label_id)
67
 
68
  def predict(self, text):
69
- encoding = self.tokenizer([text], truncation=True,padding=True, max_length=512, return_tensors="pt")
70
  encoding = {k: v.to(device) for k, v in encoding.items()}
71
 
72
  # Perform prediction
@@ -106,16 +105,19 @@ def ner_inference(text):
106
  start_idx += 1
107
  doc.ents = ents # Set the entities in the Doc
108
 
109
- # Render using spacy displacy
110
  html = displacy.render(doc, style="ent", jupyter=False) # Generate HTML for entities
111
  return html
112
 
 
 
 
113
  # Create Gradio interface
114
  import gradio as gr
115
 
116
  iface = gr.Interface(
117
  fn=ner_inference, # The function to call for prediction
118
- inputs=gr.Textbox(lines=5, placeholder="Enter Japanese text for NER..."), # Input widget
119
  outputs="html", # Output will be in HTML format using displacy
120
  title="Japanese Named Entity Recognition (NER)",
121
  description="Enter Japanese text and see the named entities highlighted in the output."
 
 
1
  # -*- coding: utf-8 -*-
2
  """
3
  Created on Tue Sep 17 19:03:17 2024
 
52
  sample_encoding = self.tokenizer([
53
  "鈴木は4月の陽気の良い日に、鈴をつけて熊本県の阿蘇山に登った",
54
  "中国では、中国共産党による一党統治が続く",
55
+ ], truncation=True, padding=True, # Ensure all sequences are of the same length
56
  max_length=512, return_tensors="pt")
57
 
58
  sample_encoding = {k: v.to(device) for k, v in sample_encoding.items()}
 
65
  print("Predicted labels:", predicted_label_id)
66
 
67
  def predict(self, text):
68
+ encoding = self.tokenizer([text], truncation=True, padding=True, max_length=512, return_tensors="pt")
69
  encoding = {k: v.to(device) for k, v in encoding.items()}
70
 
71
  # Perform prediction
 
105
  start_idx += 1
106
  doc.ents = ents # Set the entities in the Doc
107
 
108
+ # Render using spaCy displacy
109
  html = displacy.render(doc, style="ent", jupyter=False) # Generate HTML for entities
110
  return html
111
 
112
+ # Sample text for demonstration
113
+ sample_text = "鈴木一朗は2020年に引退した。女優の石原さとみは多くの映画で主演している。"
114
+
115
  # Create Gradio interface
116
  import gradio as gr
117
 
118
  iface = gr.Interface(
119
  fn=ner_inference, # The function to call for prediction
120
+ inputs=gr.Textbox(lines=5, placeholder="Enter Japanese text for NER...", default=sample_text), # Input widget with sample text
121
  outputs="html", # Output will be in HTML format using displacy
122
  title="Japanese Named Entity Recognition (NER)",
123
  description="Enter Japanese text and see the named entities highlighted in the output."