Spaces:
Running
on
Zero
Running
on
Zero
Fix save
Browse files
app.py
CHANGED
|
@@ -4,6 +4,8 @@ import gradio as gr
|
|
| 4 |
from download_url import download_text_and_title
|
| 5 |
from cache_system import CacheHandler
|
| 6 |
from gradio_client import Client
|
|
|
|
|
|
|
| 7 |
|
| 8 |
print(f"CPU cores: {os.cpu_count()}.")
|
| 9 |
|
|
@@ -13,6 +15,36 @@ auth_token = os.environ.get("TOKEN") or True
|
|
| 13 |
client = Client(server)
|
| 14 |
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
def finish_generation(text: str) -> str:
|
| 17 |
return f"{text}\n\n⬇️ Ayuda a mejorar la herramienta marcando si el resumen es correcto o no.⬇️"
|
| 18 |
|
|
@@ -86,7 +118,10 @@ def generate_text(
|
|
| 86 |
|
| 87 |
|
| 88 |
cache_handler = CacheHandler(max_cache_size=1000)
|
| 89 |
-
hf_writer =
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
demo = gr.Interface(
|
| 92 |
generate_text,
|
|
|
|
| 4 |
from download_url import download_text_and_title
|
| 5 |
from cache_system import CacheHandler
|
| 6 |
from gradio_client import Client
|
| 7 |
+
from collections import OrderedDict
|
| 8 |
+
from typing import Any
|
| 9 |
|
| 10 |
print(f"CPU cores: {os.cpu_count()}.")
|
| 11 |
|
|
|
|
| 15 |
client = Client(server)
|
| 16 |
|
| 17 |
|
| 18 |
+
class HuggingFaceDatasetSaver_custom(gr.HuggingFaceDatasetSaver):
|
| 19 |
+
def _deserialize_components(
|
| 20 |
+
self,
|
| 21 |
+
data_dir,
|
| 22 |
+
flag_data: list[Any],
|
| 23 |
+
flag_option: str = "",
|
| 24 |
+
username: str = "",
|
| 25 |
+
) -> tuple[dict[Any, Any], list[Any]]:
|
| 26 |
+
"""Deserialize components and return the corresponding row for the flagged sample.
|
| 27 |
+
|
| 28 |
+
Images/audio are saved to disk as individual files.
|
| 29 |
+
"""
|
| 30 |
+
# Components that can have a preview on dataset repos
|
| 31 |
+
file_preview_types = {gr.Audio: "Audio", gr.Image: "Image"}
|
| 32 |
+
|
| 33 |
+
# Generate the row corresponding to the flagged sample
|
| 34 |
+
features = OrderedDict()
|
| 35 |
+
row = []
|
| 36 |
+
for component, sample in zip(self.components, flag_data):
|
| 37 |
+
label = component.label or ""
|
| 38 |
+
features[label] = {"dtype": "string", "_type": "Value"}
|
| 39 |
+
row.append(sample)
|
| 40 |
+
|
| 41 |
+
features["flag"] = {"dtype": "string", "_type": "Value"}
|
| 42 |
+
features["username"] = {"dtype": "string", "_type": "Value"}
|
| 43 |
+
row.append(flag_option)
|
| 44 |
+
row.append(username)
|
| 45 |
+
return features, row
|
| 46 |
+
|
| 47 |
+
|
| 48 |
def finish_generation(text: str) -> str:
|
| 49 |
return f"{text}\n\n⬇️ Ayuda a mejorar la herramienta marcando si el resumen es correcto o no.⬇️"
|
| 50 |
|
|
|
|
| 118 |
|
| 119 |
|
| 120 |
cache_handler = CacheHandler(max_cache_size=1000)
|
| 121 |
+
hf_writer = HuggingFaceDatasetSaver_custom(
|
| 122 |
+
auth_token, "Iker/Clickbait-News", private=True, separate_dirs=False
|
| 123 |
+
)
|
| 124 |
+
|
| 125 |
|
| 126 |
demo = gr.Interface(
|
| 127 |
generate_text,
|