Spaces:
Sleeping
Sleeping
juhoinkinen
commited on
Commit
•
a7a561c
1
Parent(s):
946d5fe
Use html and css for plotting instead of plotly
Browse files- app.py +42 -54
- requirements.txt +0 -1
app.py
CHANGED
@@ -51,61 +51,49 @@ def process(image, project_num: int, lang: str = "eng"):
|
|
51 |
|
52 |
results = annif.suggest(project_id=proj_ids[project_num], text=text)
|
53 |
|
54 |
-
#
|
55 |
sorted_results = sorted(results, key=lambda x: x['score'], reverse=True)
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
fig.update_layout(showlegend=False)
|
96 |
-
|
97 |
-
# Add invisible scatter plots to push bars to the left
|
98 |
-
fig.add_trace(go.Scatter(
|
99 |
-
x=[0]*len(labels),
|
100 |
-
y=labels,
|
101 |
-
mode='markers',
|
102 |
-
marker=dict(color='rgba(0,0,0,0)'),
|
103 |
-
showlegend=False,
|
104 |
-
))
|
105 |
-
|
106 |
-
return text, fig
|
107 |
except Exception as e:
|
108 |
-
return str(e),
|
109 |
|
110 |
|
111 |
langs = ("eng", "fin", "swe")
|
@@ -120,7 +108,7 @@ interface = gr.Interface(
|
|
120 |
],
|
121 |
outputs=[
|
122 |
"text",
|
123 |
-
gr.
|
124 |
],
|
125 |
css="footer {visibility: hidden}",
|
126 |
title="Annif demo using Optical Character Recognition",
|
|
|
51 |
|
52 |
results = annif.suggest(project_id=proj_ids[project_num], text=text)
|
53 |
|
54 |
+
# Sort results by score in descending order
|
55 |
sorted_results = sorted(results, key=lambda x: x['score'], reverse=True)
|
56 |
+
|
57 |
+
# Generate HTML for results
|
58 |
+
html_content = """
|
59 |
+
<style>
|
60 |
+
.results-container {
|
61 |
+
font-family: Arial, sans-serif;
|
62 |
+
width: 300px;
|
63 |
+
}
|
64 |
+
.result-item {
|
65 |
+
display: flex;
|
66 |
+
align-items: center;
|
67 |
+
margin-bottom: 5px;
|
68 |
+
}
|
69 |
+
.bar {
|
70 |
+
background-color: #B4D5FE;
|
71 |
+
height: 20px;
|
72 |
+
margin-right: 10px;
|
73 |
+
}
|
74 |
+
.label {
|
75 |
+
flex-grow: 1;
|
76 |
+
font-size: 14px;
|
77 |
+
}
|
78 |
+
</style>
|
79 |
+
<div class="results-container">
|
80 |
+
<h3 style="margin-bottom: 15px;">SUGGESTED SUBJECTS</h3>
|
81 |
+
"""
|
82 |
+
|
83 |
+
for result in sorted_results:
|
84 |
+
bar_width = result['score'] * 100 # Scale the score to percentage
|
85 |
+
html_content += f"""
|
86 |
+
<div class="result-item">
|
87 |
+
<div class="bar" style="width: {bar_width}%;"></div>
|
88 |
+
<div class="label">{result['label']}</div>
|
89 |
+
</div>
|
90 |
+
"""
|
91 |
+
|
92 |
+
html_content += "</div>"
|
93 |
+
|
94 |
+
return text, html_content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
except Exception as e:
|
96 |
+
return str(e), ""
|
97 |
|
98 |
|
99 |
langs = ("eng", "fin", "swe")
|
|
|
108 |
],
|
109 |
outputs=[
|
110 |
"text",
|
111 |
+
gr.HTML(),
|
112 |
],
|
113 |
css="footer {visibility: hidden}",
|
114 |
title="Annif demo using Optical Character Recognition",
|
requirements.txt
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
pytesseract
|
2 |
gradio
|
3 |
opencv-python
|
4 |
-
plotly
|
5 |
annif-client
|
|
|
1 |
pytesseract
|
2 |
gradio
|
3 |
opencv-python
|
|
|
4 |
annif-client
|