Spaces:
Running
Running
juhoinkinen
commited on
Format plot to use horizontal bars and resemble Annif Web UI
Browse files
app.py
CHANGED
@@ -55,14 +55,40 @@ def process(image, project_num: int, lang: str = "eng"):
|
|
55 |
labels = [res['label'] for res in results]
|
56 |
scores = [res['score'] for res in results]
|
57 |
|
58 |
-
# Create a bar plot
|
59 |
-
fig = go.Figure(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
fig.update_layout(
|
61 |
-
title="
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
)
|
65 |
|
|
|
|
|
|
|
66 |
return text, fig
|
67 |
except Exception as e:
|
68 |
return str(e), None
|
|
|
55 |
labels = [res['label'] for res in results]
|
56 |
scores = [res['score'] for res in results]
|
57 |
|
58 |
+
# Create a horizontal bar plot
|
59 |
+
fig = go.Figure()
|
60 |
+
|
61 |
+
# Add bars
|
62 |
+
fig.add_trace(go.Bar(
|
63 |
+
y=labels[::-1], # Reverse order to have highest score at top
|
64 |
+
x=scores[::-1],
|
65 |
+
orientation='h',
|
66 |
+
marker_color='lightblue',
|
67 |
+
width=0.6, # Adjust bar width
|
68 |
+
))
|
69 |
+
|
70 |
+
# Customize the layout
|
71 |
fig.update_layout(
|
72 |
+
title="SUGGESTED SUBJECTS",
|
73 |
+
title_font=dict(size=16, color='black', family='Arial, sans-serif'),
|
74 |
+
xaxis=dict(
|
75 |
+
title=None,
|
76 |
+
showticklabels=False,
|
77 |
+
showgrid=False,
|
78 |
+
zeroline=False,
|
79 |
+
),
|
80 |
+
yaxis=dict(
|
81 |
+
title=None,
|
82 |
+
tickfont=dict(size=12, color='black', family='Arial, sans-serif'),
|
83 |
+
),
|
84 |
+
margin=dict(l=10, r=10, t=40, b=10),
|
85 |
+
height=400,
|
86 |
+
plot_bgcolor='white',
|
87 |
)
|
88 |
|
89 |
+
# Remove the plotly logo
|
90 |
+
fig.update_layout(showlegend=False)
|
91 |
+
|
92 |
return text, fig
|
93 |
except Exception as e:
|
94 |
return str(e), None
|