Rakibul
commited on
Commit
·
5a5588f
1
Parent(s):
3763495
running fine
Browse files
app.py
CHANGED
|
@@ -27,10 +27,17 @@ def _warmup():
|
|
| 27 |
return f"Model loaded in {time.time() - t0:.1f} seconds."
|
| 28 |
|
| 29 |
def ci_plot(mean: float, low: float, upp: float):
|
| 30 |
-
fig, ax = plt.subplots(figsize=(6, 1.
|
| 31 |
-
ax.
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
ax.set_xlim(0, 100)
|
| 35 |
ax.set_yticks([])
|
| 36 |
ax.set_xlabel("Empathy Score (0-100) +/- 95% CI")
|
|
@@ -42,9 +49,10 @@ def predict_with_ci(essay: str, article: str) -> tuple[float, float, float, plt.
|
|
| 42 |
mean, var = predict(essay, article)
|
| 43 |
# scores were originally in [1, 7]
|
| 44 |
# lets scale them to [0, 100]
|
| 45 |
-
|
|
|
|
|
|
|
| 46 |
|
| 47 |
-
std = np.sqrt(var)
|
| 48 |
ci_low = max(0.0, mean - 1.96 * std)
|
| 49 |
ci_upp = min(100.0, mean + 1.96 * std)
|
| 50 |
fig = ci_plot(mean, ci_low, ci_upp)
|
|
@@ -55,9 +63,18 @@ with gr.Blocks(title="UPLME", theme=Soft(primary_hue="blue")) as demo:
|
|
| 55 |
gr.Markdown("# Empathy Prediction with Uncertainty Estimation")
|
| 56 |
with gr.Row():
|
| 57 |
with gr.Column():
|
| 58 |
-
essay_input = gr.Textbox(label="Response (E.g., Essay) towards the stimulus", lines=
|
| 59 |
-
article_input = gr.Textbox(label="Stimulus (E.g., News Article)", lines=
|
| 60 |
button = gr.Button("Predict")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
with gr.Column():
|
| 62 |
output_mean = gr.Number(label="Predicted Empathy Score (0-100)", precision=2)
|
| 63 |
ci_low = gr.Number(label="95% CI Lower Bound", precision=2)
|
|
@@ -65,7 +82,7 @@ with gr.Blocks(title="UPLME", theme=Soft(primary_hue="blue")) as demo:
|
|
| 65 |
|
| 66 |
fig = gr.Plot(show_label=False)
|
| 67 |
|
| 68 |
-
button.click(fn=predict_with_ci, inputs=[essay_input, article_input], outputs=[output_mean, ci_low, ci_upp, fig])
|
| 69 |
|
| 70 |
gr.Markdown("## About")
|
| 71 |
gr.Markdown("""
|
|
|
|
| 27 |
return f"Model loaded in {time.time() - t0:.1f} seconds."
|
| 28 |
|
| 29 |
def ci_plot(mean: float, low: float, upp: float):
|
| 30 |
+
fig, ax = plt.subplots(figsize=(6, 1.4))
|
| 31 |
+
ax.errorbar(
|
| 32 |
+
x=mean, y=0,
|
| 33 |
+
xerr=[[mean - low], [upp - mean]],
|
| 34 |
+
fmt='o', color='blue',
|
| 35 |
+
ecolor='orange',
|
| 36 |
+
elinewidth=5,
|
| 37 |
+
capsize=8,
|
| 38 |
+
capthick=4,
|
| 39 |
+
markersize=10
|
| 40 |
+
)
|
| 41 |
ax.set_xlim(0, 100)
|
| 42 |
ax.set_yticks([])
|
| 43 |
ax.set_xlabel("Empathy Score (0-100) +/- 95% CI")
|
|
|
|
| 49 |
mean, var = predict(essay, article)
|
| 50 |
# scores were originally in [1, 7]
|
| 51 |
# lets scale them to [0, 100]
|
| 52 |
+
scale = 100 / 6
|
| 53 |
+
mean = (mean - 1) * scale
|
| 54 |
+
std = np.sqrt(var) * scale
|
| 55 |
|
|
|
|
| 56 |
ci_low = max(0.0, mean - 1.96 * std)
|
| 57 |
ci_upp = min(100.0, mean + 1.96 * std)
|
| 58 |
fig = ci_plot(mean, ci_low, ci_upp)
|
|
|
|
| 63 |
gr.Markdown("# Empathy Prediction with Uncertainty Estimation")
|
| 64 |
with gr.Row():
|
| 65 |
with gr.Column():
|
| 66 |
+
essay_input = gr.Textbox(label="Response (E.g., Essay) towards the stimulus", lines=6)
|
| 67 |
+
article_input = gr.Textbox(label="Stimulus (E.g., News Article)", lines=6)
|
| 68 |
button = gr.Button("Predict")
|
| 69 |
+
|
| 70 |
+
gr.Examples(
|
| 71 |
+
examples=[
|
| 72 |
+
["My heart just breaks for the people who are suffering.", "A month after Hurricane Matthew, 800,000 Haitians urgently need food."],
|
| 73 |
+
["I see, but this doesn't sound too worrisome to me.", "A month after Hurricane Matthew, 800,000 Haitians urgently need food."],
|
| 74 |
+
],
|
| 75 |
+
inputs=[essay_input, article_input],
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
with gr.Column():
|
| 79 |
output_mean = gr.Number(label="Predicted Empathy Score (0-100)", precision=2)
|
| 80 |
ci_low = gr.Number(label="95% CI Lower Bound", precision=2)
|
|
|
|
| 82 |
|
| 83 |
fig = gr.Plot(show_label=False)
|
| 84 |
|
| 85 |
+
button.click(fn=predict_with_ci, inputs=[essay_input, article_input], outputs=[output_mean, ci_low, ci_upp, fig])
|
| 86 |
|
| 87 |
gr.Markdown("## About")
|
| 88 |
gr.Markdown("""
|