Spaces:
Runtime error
Runtime error
Update app.py
Browse files13 unmodified lines14151617181966 unmodified lines868788899091929394959697989910010110210310410510610710810911011113 unmodified linesimport osimport colorsysimport matplotlib.pyplot as pltdef hex_to_rgb(hex_color: str) -> tuple[int, int, int]:hex_color = hex_color.lstrip('#')66 unmodified linesscore = prediction1 / (prediction2 + prediction1)return f"{round(prediction1, 1)}", f"{round(prediction2, 1)}", f"{round(score, 2)}"def generate_charts(ner_output_bin: dict, ner_output_ext: dict) -> Tuple[plt.Figure, plt.Figure]:entities_bin = [entity['entity'] for entity in ner_output_bin['entities']]entities_ext = [entity['entity'] for entity in ner_output_ext['entities']]all_entities = entities_bin + entities_extentity_counts = {entity: all_entities.count(entity) for entity in set(all_entities)}pie_labels = list(entity_counts.keys())pie_sizes = list(entity_counts.values())fig1, ax1 = plt.subplots()ax1.pie(pie_sizes, labels=pie_labels, autopct='%1.1f%%', startangle=90)ax1.axis('equal')fig2, ax2 = plt.subplots()ax2.bar(entity_counts.keys(), entity_counts.values())ax2.set_ylabel('Count')ax2.set_xlabel('Entity Type')ax2.set_title('Entity Counts')return fig1, fig213 unmodified lines14151617181920212266 unmodified lines899091929394959697989910010110210310410510610710810911011111211311411511611711811912013 unmodified linesimport osimport colorsysimport matplotlib.pyplot as pltimport plotly.graph_objects as gofrom typing import Tupleimport plotly.io as piodef hex_to_rgb(hex_color: str) -> tuple[int, int, int]:hex_color = hex_color.lstrip('#')66 unmodified linesscore = prediction1 / (prediction2 + prediction1)return f"{round(prediction1, 1)}", f"{round(prediction2, 1)}", f"{round(score, 2)}"def generate_charts(ner_output_bin: dict, ner_output_ext: dict) -> Tuple[go.Figure, go.Figure]:entities_bin = [entity['entity'] for entity in ner_output_bin['entities']]entities_ext = [entity['entity'] for entity in ner_output_ext['entities']]# Counting entities for binary classificationentity_counts_bin = {entity: entities_bin.count(entity) for entity in set(entities_bin)}bin_labels = list(entity_counts_bin.keys())bin_sizes = list(entity_counts_bin.values())# Counting entities for extended classificationentity_counts_ext = {entity: entities_ext.count(entity) for entity in set(entities_ext)}ext_labels = list(entity_counts_ext.keys())ext_sizes = list(entity_counts_ext.values())# Create pie chart for extended classificationfig1 = go.Figure(data=[go.Pie(labels=ext_labels, values=ext_sizes, textinfo='label+percent', hole=.3)])fig1.update_layout(title_text='Extended Sequence Classification Subclasses')# Create bar chart for binary classificationfig2 = go.Figure(data=[go.Bar(x=bin_labels, y=bin_sizes)])fig2.update_layout(title='Binary Sequence Classification Classes',xaxis_title='Entity Type',yaxis_title='Count')return fig1, fig2
app.py+24-15