Spaces:
Sleeping
Sleeping
Updatze: Buttons
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import types # für Instanz-Monkeypatch (fastText .predict)
|
|
| 4 |
import html # HTML-Escaping für Ausgabe/Gradio
|
| 5 |
import numpy as np # Numerik (z.B. für Wahrscheinlichkeiten)
|
| 6 |
import time
|
|
|
|
| 7 |
|
| 8 |
# Machine Learning / NLP
|
| 9 |
import torch # PyTorch (Model, Tensor, Device)
|
|
@@ -161,39 +162,35 @@ def predict(review: str):
|
|
| 161 |
|
| 162 |
##################################################################################
|
| 163 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
def replace_text():
|
| 165 |
-
|
| 166 |
-
return "Fresh apples, honey, vanilla and a touch of smoke."
|
| 167 |
|
| 168 |
### Create Form interface with Gradio Framework ##################################
|
| 169 |
-
with gr.Blocks() as
|
| 170 |
-
gr.Markdown("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
|
|
|
|
| 172 |
with gr.Row():
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
lines=8,
|
| 176 |
-
placeholder="Enter whisky review",
|
| 177 |
-
value="Honey roasted figs, cloves and sticky toffee pudding with a suggestive smokiness evocative of barbecued bananas."
|
| 178 |
-
)
|
| 179 |
-
replace_btn = gr.Button("🔄 Replace Example")
|
| 180 |
-
|
| 181 |
-
submit_btn = gr.Button("Submit")
|
| 182 |
|
| 183 |
html_out = gr.HTML(label="Table")
|
| 184 |
json_out = gr.JSON(label="JSON")
|
| 185 |
|
| 186 |
# Events
|
| 187 |
-
submit_btn.click(
|
| 188 |
-
|
| 189 |
-
inputs=[review_box],
|
| 190 |
-
outputs=[html_out, json_out]
|
| 191 |
-
)
|
| 192 |
-
|
| 193 |
-
replace_btn.click(
|
| 194 |
-
fn=replace_text,
|
| 195 |
-
inputs=[],
|
| 196 |
-
outputs=[review_box]
|
| 197 |
-
)
|
| 198 |
|
| 199 |
-
|
|
|
|
| 4 |
import html # HTML-Escaping für Ausgabe/Gradio
|
| 5 |
import numpy as np # Numerik (z.B. für Wahrscheinlichkeiten)
|
| 6 |
import time
|
| 7 |
+
import random
|
| 8 |
|
| 9 |
# Machine Learning / NLP
|
| 10 |
import torch # PyTorch (Model, Tensor, Device)
|
|
|
|
| 162 |
|
| 163 |
##################################################################################
|
| 164 |
|
| 165 |
+
EXAMPLES = [
|
| 166 |
+
"Fresh apples, honey, vanilla and a touch of smoke.",
|
| 167 |
+
"Thick sherry, raisins and dark chocolate with gentle peat.",
|
| 168 |
+
]
|
| 169 |
+
|
| 170 |
def replace_text():
|
| 171 |
+
return random.choice(EXAMPLES)
|
|
|
|
| 172 |
|
| 173 |
### Create Form interface with Gradio Framework ##################################
|
| 174 |
+
with gr.Blocks() as demo:
|
| 175 |
+
gr.Markdown("## Submit Whisky Review for Classification")
|
| 176 |
+
|
| 177 |
+
review_box = gr.Textbox(
|
| 178 |
+
label="Whisky Review",
|
| 179 |
+
lines=8,
|
| 180 |
+
placeholder="Enter whisky review",
|
| 181 |
+
value=EXAMPLES[0],
|
| 182 |
+
)
|
| 183 |
|
| 184 |
+
# Buttons nebeneinander unter der Textbox
|
| 185 |
with gr.Row():
|
| 186 |
+
replace_btn = gr.Button("🔄 Replace Example", variant="secondary", scale=2)
|
| 187 |
+
submit_btn = gr.Button("Submit", variant="primary", scale=2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
|
| 189 |
html_out = gr.HTML(label="Table")
|
| 190 |
json_out = gr.JSON(label="JSON")
|
| 191 |
|
| 192 |
# Events
|
| 193 |
+
submit_btn.click(predict, inputs=review_box, outputs=[html_out, json_out])
|
| 194 |
+
replace_btn.click(replace_text, outputs=review_box)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
|
| 196 |
+
demo.launch()
|