AlGe commited on
Commit
bf036e1
·
verified ·
1 Parent(s): 65f249c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -7,6 +7,7 @@ import torch
7
  from transformers import AutoTokenizer, AutoModelForSequenceClassification, AutoModelForTokenClassification, pipeline
8
  import os
9
  import plotly.graph_objects as go
 
10
 
11
  # Utility functions for color conversions and brightness adjustment
12
  def hex_to_rgb(hex_color: str) -> tuple[int, int, int]:
@@ -86,9 +87,7 @@ def process_classification(text, model1, model2, tokenizer1) -> Tuple[float, flo
86
  def generate_pie_chart(values: list, labels: list, title: str):
87
  fig = go.Figure(data=[go.Pie(labels=labels, values=values, hole=.3)])
88
  fig.update_layout(title_text=title)
89
- file_path = "/tmp/pie_chart.html"
90
- fig.write_html(file_path)
91
- return file_path
92
 
93
  @spaces.GPU
94
  def all(text):
@@ -97,12 +96,12 @@ def all(text):
97
  int_count, ext_count, int_ext_ratio = process_classification(text, model1, model2, tokenizer1)
98
 
99
  # Create pie charts
100
- pie_chart_path_int_ext = generate_pie_chart([int_count, ext_count], ['Internal', 'External'], "Internal vs External Details")
101
  subclass_labels = [entity['entity'] for entity in ner_ext['entities']]
102
  subclass_values = [1] * len(subclass_labels) # Each entity is counted once; adjust as needed for actual counts
103
- pie_chart_path_subclass = generate_pie_chart(subclass_values, subclass_labels, "Detail Subclasses")
104
 
105
- return ner_bin, ner_ext, f"{round(int_count, 1)}", f"{round(ext_count, 1)}", f"{round(int_ext_ratio, 2)}", pie_chart_path_int_ext, pie_chart_path_subclass
106
 
107
  examples = [
108
  ['Bevor ich meinen Hund kaufte bin ich immer alleine durch den Park gelaufen. Gestern war ich aber mit dem Hund losgelaufen. Das Wetter war sehr schön, nicht wie sonst im Winter. Ich weiß nicht genau. Mir fällt sonst nichts dazu ein. Wir trafen auf mehrere Spaziergänger. Ein Mann mit seinem Kind. Das Kind hat ein Eis gegessen.'],
@@ -130,4 +129,4 @@ iface = gr.Interface(
130
  )
131
 
132
  # Launch the interface
133
- iface.launch(debug=True)
 
7
  from transformers import AutoTokenizer, AutoModelForSequenceClassification, AutoModelForTokenClassification, pipeline
8
  import os
9
  import plotly.graph_objects as go
10
+ import colorsys
11
 
12
  # Utility functions for color conversions and brightness adjustment
13
  def hex_to_rgb(hex_color: str) -> tuple[int, int, int]:
 
87
  def generate_pie_chart(values: list, labels: list, title: str):
88
  fig = go.Figure(data=[go.Pie(labels=labels, values=values, hole=.3)])
89
  fig.update_layout(title_text=title)
90
+ return fig.to_html(full_html=False)
 
 
91
 
92
  @spaces.GPU
93
  def all(text):
 
96
  int_count, ext_count, int_ext_ratio = process_classification(text, model1, model2, tokenizer1)
97
 
98
  # Create pie charts
99
+ pie_chart_html_int_ext = generate_pie_chart([int_count, ext_count], ['Internal', 'External'], "Internal vs External Details")
100
  subclass_labels = [entity['entity'] for entity in ner_ext['entities']]
101
  subclass_values = [1] * len(subclass_labels) # Each entity is counted once; adjust as needed for actual counts
102
+ pie_chart_html_subclass = generate_pie_chart(subclass_values, subclass_labels, "Detail Subclasses")
103
 
104
+ return ner_bin, ner_ext, f"{round(int_count, 1)}", f"{round(ext_count, 1)}", f"{round(int_ext_ratio, 2)}", pie_chart_html_int_ext, pie_chart_html_subclass
105
 
106
  examples = [
107
  ['Bevor ich meinen Hund kaufte bin ich immer alleine durch den Park gelaufen. Gestern war ich aber mit dem Hund losgelaufen. Das Wetter war sehr schön, nicht wie sonst im Winter. Ich weiß nicht genau. Mir fällt sonst nichts dazu ein. Wir trafen auf mehrere Spaziergänger. Ein Mann mit seinem Kind. Das Kind hat ein Eis gegessen.'],
 
129
  )
130
 
131
  # Launch the interface
132
+ iface.launch(debug=True)