Update app.py
Browse files
app.py
CHANGED
|
@@ -40,7 +40,9 @@ def predict(texts, threshold=0.3):
|
|
| 40 |
def predict_bulk(texts_str, threshold=0.3):
|
| 41 |
texts = [line.strip() for line in texts_str.split("\n") if line.strip()]
|
| 42 |
results = predict(texts, threshold)
|
| 43 |
-
|
|
|
|
|
|
|
| 44 |
|
| 45 |
# Process CSV file upload
|
| 46 |
def predict_file(file_obj, threshold=0.3):
|
|
@@ -55,13 +57,13 @@ def predict_file(file_obj, threshold=0.3):
|
|
| 55 |
return out_path
|
| 56 |
|
| 57 |
with gr.Blocks() as demo:
|
| 58 |
-
gr.Markdown("#
|
| 59 |
|
| 60 |
thr = gr.Slider(0.1, 0.9, 0.3, label="Threshold")
|
| 61 |
|
| 62 |
with gr.Tab("Paste Text (one per line)"):
|
| 63 |
inp = gr.Textbox(label="Enter texts (one per line)", lines=10, placeholder="Enter sentences here")
|
| 64 |
-
out = gr.
|
| 65 |
btn = gr.Button("Analyze")
|
| 66 |
btn.click(fn=predict_bulk, inputs=[inp, thr], outputs=out)
|
| 67 |
|
|
|
|
| 40 |
def predict_bulk(texts_str, threshold=0.3):
|
| 41 |
texts = [line.strip() for line in texts_str.split("\n") if line.strip()]
|
| 42 |
results = predict(texts, threshold)
|
| 43 |
+
# Format with bold emotions
|
| 44 |
+
formatted = "\n".join(f"{t}: " + ", ".join(f"**{e}**" for e in r.split(", ")) for t, r in zip(texts, results))
|
| 45 |
+
return formatted
|
| 46 |
|
| 47 |
# Process CSV file upload
|
| 48 |
def predict_file(file_obj, threshold=0.3):
|
|
|
|
| 57 |
return out_path
|
| 58 |
|
| 59 |
with gr.Blocks() as demo:
|
| 60 |
+
gr.Markdown("# 🦄 GoEmotions Multi-Label Demo")
|
| 61 |
|
| 62 |
thr = gr.Slider(0.1, 0.9, 0.3, label="Threshold")
|
| 63 |
|
| 64 |
with gr.Tab("Paste Text (one per line)"):
|
| 65 |
inp = gr.Textbox(label="Enter texts (one per line)", lines=10, placeholder="Enter sentences here")
|
| 66 |
+
out = gr.Markdown(label="Predicted emotions")
|
| 67 |
btn = gr.Button("Analyze")
|
| 68 |
btn.click(fn=predict_bulk, inputs=[inp, thr], outputs=out)
|
| 69 |
|