patrixtano commited on
Commit
eb519d4
·
verified ·
1 Parent(s): 427a910

removing output highlighting

Browse files
Files changed (1) hide show
  1. app.py +2 -23
app.py CHANGED
@@ -1,30 +1,9 @@
1
  import gradio as gr
2
- import re
3
  from transformers import pipeline, AutoTokenizer
4
  # Load the Hugging Face model
5
  model_path = "patrixtano/mt5-base-anaphora_czech_6e"
6
  model_pipeline = pipeline("text2text-generation", model=model_path)
7
  tokenizer = AutoTokenizer.from_pretrained("patrixtano/mt5-base-anaphora_czech_6e")
8
-
9
- def split_sentence_with_tags(sentence):
10
- # Regular expression to match <ana></ana>, <ant></ant>, or regular words
11
- pattern = r'<ana>.*?</ana>|<ant>.*?</ant>|\S+'
12
-
13
- # Find all matches in the sentence
14
- words = re.findall(pattern, sentence)
15
-
16
- # Create categories list
17
- categories = []
18
- for word in words:
19
- if word.startswith('<ana>') and word.endswith('</ana>'):
20
- categories.append("ANA")
21
- elif word.startswith('<ant>') and word.endswith('</ant>'):
22
- categories.append("ANT")
23
- else:
24
- categories.append("-")
25
-
26
- return words, categories
27
-
28
  def predict(text_input):
29
  """
30
  Generate a prediction for the given input text using the Hugging Face model.
@@ -37,7 +16,7 @@ def predict(text_input):
37
  try:
38
  result = model_pipeline(text_input, **generation_parameters)
39
  # Extract and return the generated text
40
- return split_sentence_with_tags(result[0]["generated_text"])
41
  except Exception as e:
42
  return f"Error: {str(e)}"
43
 
@@ -49,7 +28,7 @@ examples = ["""Miluji ženu s vařečkou, <ana>která</ana> umí vařit.""",
49
  interface = gr.Interface(
50
  fn=predict,
51
  inputs=gr.Textbox(lines=5, label="Input Text"),
52
- outputs=gr.HighlightedText(label="Model Output", show_legend=True, color_map={"ANA": "#f7a7a3", "ANT": "#87CEFF"}),
53
  title="Anaphora resolution demo",
54
  description="""Enter text into the \"Input Text\" box, include <ana> </ana> tags around the anaphora
55
  which is to be resolved. The model generates a copy of the text with <ant> </ant> tags marking the
 
1
  import gradio as gr
 
2
  from transformers import pipeline, AutoTokenizer
3
  # Load the Hugging Face model
4
  model_path = "patrixtano/mt5-base-anaphora_czech_6e"
5
  model_pipeline = pipeline("text2text-generation", model=model_path)
6
  tokenizer = AutoTokenizer.from_pretrained("patrixtano/mt5-base-anaphora_czech_6e")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  def predict(text_input):
8
  """
9
  Generate a prediction for the given input text using the Hugging Face model.
 
16
  try:
17
  result = model_pipeline(text_input, **generation_parameters)
18
  # Extract and return the generated text
19
+ return result[0]["generated_text"]
20
  except Exception as e:
21
  return f"Error: {str(e)}"
22
 
 
28
  interface = gr.Interface(
29
  fn=predict,
30
  inputs=gr.Textbox(lines=5, label="Input Text"),
31
+ outputs=gr.Textbox(label="Model Output"),
32
  title="Anaphora resolution demo",
33
  description="""Enter text into the \"Input Text\" box, include <ana> </ana> tags around the anaphora
34
  which is to be resolved. The model generates a copy of the text with <ant> </ant> tags marking the