Spaces:
Sleeping
Sleeping
Commit ·
e17e016
1
Parent(s): c747f16
Fixed Errors with Sample Text Analyzing on Gradio Demo- Attempt 2
Browse files- scripts/demo_gradio.py +2 -8
scripts/demo_gradio.py
CHANGED
|
@@ -4,7 +4,6 @@ Showcases summarization, emotion detection, and topic prediction.
|
|
| 4 |
"""
|
| 5 |
import json
|
| 6 |
import sys
|
| 7 |
-
from io import BytesIO
|
| 8 |
from pathlib import Path
|
| 9 |
from typing import Iterable, Sequence
|
| 10 |
import gradio as gr
|
|
@@ -291,7 +290,7 @@ def prepare_download(
|
|
| 291 |
summary: str,
|
| 292 |
emotions: EmotionPrediction | dict[str, Sequence[float] | Sequence[str]],
|
| 293 |
topic: TopicPrediction | dict[str, float | str],
|
| 294 |
-
) ->
|
| 295 |
"""Prepare JSON data buffer for download."""
|
| 296 |
if isinstance(emotions, EmotionPrediction):
|
| 297 |
emotion_payload = {
|
|
@@ -315,12 +314,7 @@ def prepare_download(
|
|
| 315 |
"emotions": emotion_payload,
|
| 316 |
"topic": topic_payload,
|
| 317 |
}
|
| 318 |
-
|
| 319 |
-
buffer = BytesIO()
|
| 320 |
-
buffer.write(json.dumps(payload, ensure_ascii=False, indent=2).encode("utf-8"))
|
| 321 |
-
buffer.seek(0)
|
| 322 |
-
buffer.name = "leximind_demo_output.json"
|
| 323 |
-
return buffer
|
| 324 |
|
| 325 |
# Sample data for the demo
|
| 326 |
SAMPLE_TEXT = """
|
|
|
|
| 4 |
"""
|
| 5 |
import json
|
| 6 |
import sys
|
|
|
|
| 7 |
from pathlib import Path
|
| 8 |
from typing import Iterable, Sequence
|
| 9 |
import gradio as gr
|
|
|
|
| 290 |
summary: str,
|
| 291 |
emotions: EmotionPrediction | dict[str, Sequence[float] | Sequence[str]],
|
| 292 |
topic: TopicPrediction | dict[str, float | str],
|
| 293 |
+
) -> bytes:
|
| 294 |
"""Prepare JSON data buffer for download."""
|
| 295 |
if isinstance(emotions, EmotionPrediction):
|
| 296 |
emotion_payload = {
|
|
|
|
| 314 |
"emotions": emotion_payload,
|
| 315 |
"topic": topic_payload,
|
| 316 |
}
|
| 317 |
+
return json.dumps(payload, ensure_ascii=False, indent=2).encode("utf-8")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 318 |
|
| 319 |
# Sample data for the demo
|
| 320 |
SAMPLE_TEXT = """
|