Spaces:
Sleeping
Sleeping
Update: Remove mode option
Browse files
app.py
CHANGED
|
@@ -113,7 +113,7 @@ def is_eng(review: str):
|
|
| 113 |
|
| 114 |
### Do actual prediction #########################################################
|
| 115 |
@spaces.GPU(duration=120) # Sekunden GPU-Zeit pro Call
|
| 116 |
-
def predict(review: str
|
| 117 |
|
| 118 |
review = (review or "").strip()
|
| 119 |
|
|
@@ -131,35 +131,30 @@ def predict(review: str, mode: str):
|
|
| 131 |
prediction_flavours = predict_flavours(review, model_flavours, tokenizer_flavours, device)
|
| 132 |
t_end_flavours = time.time()
|
| 133 |
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
"
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
for name, score in prediction_flavours.items()
|
| 157 |
-
],
|
| 158 |
-
}
|
| 159 |
-
return html_out, json_out
|
| 160 |
|
| 161 |
### Create Form interface with Gradio Framework ##################################
|
| 162 |
-
|
| 163 |
iface = gr.Interface(
|
| 164 |
fn=predict,
|
| 165 |
inputs=[
|
|
@@ -168,19 +163,13 @@ iface = gr.Interface(
|
|
| 168 |
lines=8,
|
| 169 |
placeholder="Enter whisky review",
|
| 170 |
value="Honey roasted figs, cloves and sticky toffee pudding with a suggestive smokiness evocative of barbecued bananas."
|
| 171 |
-
),
|
| 172 |
-
gr.Dropdown(
|
| 173 |
-
label="Display mode",
|
| 174 |
-
choices=[("Table", "table"), ("JSON", "json")],
|
| 175 |
-
value="table"
|
| 176 |
)
|
| 177 |
],
|
| 178 |
outputs=[
|
| 179 |
gr.HTML(label="Table"),
|
| 180 |
gr.JSON(label="JSON"),
|
| 181 |
],
|
| 182 |
-
title="Submit Whisky Review for Classification"
|
| 183 |
-
# description="Paste an English whisky review, choose display mode, then submit.",
|
| 184 |
)
|
| 185 |
|
| 186 |
iface.launch()
|
|
|
|
| 113 |
|
| 114 |
### Do actual prediction #########################################################
|
| 115 |
@spaces.GPU(duration=120) # Sekunden GPU-Zeit pro Call
|
| 116 |
+
def predict(review: str):
|
| 117 |
|
| 118 |
review = (review or "").strip()
|
| 119 |
|
|
|
|
| 131 |
prediction_flavours = predict_flavours(review, model_flavours, tokenizer_flavours, device)
|
| 132 |
t_end_flavours = time.time()
|
| 133 |
|
| 134 |
+
html_out = f"<b>{html.escape(review)}</b>"
|
| 135 |
+
|
| 136 |
+
json_out = {
|
| 137 |
+
"review": review,
|
| 138 |
+
'model': FILENAME,
|
| 139 |
+
"device": device,
|
| 140 |
+
"duration": round((t_end_flavours - t_start_flavours), 3),
|
| 141 |
+
"is_en": {
|
| 142 |
+
"is": review_is_eng,
|
| 143 |
+
"prob": review_is_eng_prob
|
| 144 |
+
},
|
| 145 |
+
"results": [{
|
| 146 |
+
'icon': ICONS[name],
|
| 147 |
+
'name': name,
|
| 148 |
+
'score': score,
|
| 149 |
+
#'level': get_level(score)
|
| 150 |
+
}
|
| 151 |
+
for name, score in prediction_flavours.items()
|
| 152 |
+
],
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
return html_out, json_out
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
|
| 157 |
### Create Form interface with Gradio Framework ##################################
|
|
|
|
| 158 |
iface = gr.Interface(
|
| 159 |
fn=predict,
|
| 160 |
inputs=[
|
|
|
|
| 163 |
lines=8,
|
| 164 |
placeholder="Enter whisky review",
|
| 165 |
value="Honey roasted figs, cloves and sticky toffee pudding with a suggestive smokiness evocative of barbecued bananas."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
)
|
| 167 |
],
|
| 168 |
outputs=[
|
| 169 |
gr.HTML(label="Table"),
|
| 170 |
gr.JSON(label="JSON"),
|
| 171 |
],
|
| 172 |
+
title="Submit Whisky Review for Classification"
|
|
|
|
| 173 |
)
|
| 174 |
|
| 175 |
iface.launch()
|