Spaces:
Runtime error
Runtime error
Try uploading to huggingface
Browse files
app.py
CHANGED
|
@@ -4,13 +4,34 @@ import torch
|
|
| 4 |
from transformers import AutoTokenizer
|
| 5 |
import json
|
| 6 |
from datetime import datetime
|
| 7 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
tokenizer = AutoTokenizer.from_pretrained("gpt2")
|
| 10 |
|
| 11 |
# Global variable to store the latest obfuscation result
|
| 12 |
latest_obfuscation = {}
|
| 13 |
-
user_id = str(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
@spaces.GPU
|
| 16 |
def temp(text):
|
|
@@ -18,9 +39,11 @@ def temp(text):
|
|
| 18 |
return response
|
| 19 |
|
| 20 |
def save_data(data):
|
| 21 |
-
with
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
| 24 |
|
| 25 |
def save_feedback(feedback_rating, feedback_text):
|
| 26 |
global latest_obfuscation
|
|
@@ -77,7 +100,6 @@ def greet(input_text, length, function_words, grade_level, sarcasm, formality, v
|
|
| 77 |
|
| 78 |
# Save the obfuscation result
|
| 79 |
save_data(latest_obfuscation)
|
| 80 |
-
|
| 81 |
return response
|
| 82 |
|
| 83 |
def reset_sliders():
|
|
|
|
| 4 |
from transformers import AutoTokenizer
|
| 5 |
import json
|
| 6 |
from datetime import datetime
|
| 7 |
+
from uuid import uuid4
|
| 8 |
+
import os
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
print(os.getenv('HF_TOKEN'))
|
| 11 |
+
headers={"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"}
|
| 12 |
+
import requests
|
| 13 |
+
response = requests.get("https://huggingface.co/datasets/hallisky/authorship-obfuscation-demo-data", headers=headers)
|
| 14 |
+
print(response)
|
| 15 |
+
from huggingface_hub import CommitScheduler
|
| 16 |
|
| 17 |
tokenizer = AutoTokenizer.from_pretrained("gpt2")
|
| 18 |
|
| 19 |
# Global variable to store the latest obfuscation result
|
| 20 |
latest_obfuscation = {}
|
| 21 |
+
user_id = str(uuid4()) # Generate a unique session-specific user ID
|
| 22 |
+
|
| 23 |
+
JSON_DATASET_DIR = Path("json_dataset")
|
| 24 |
+
JSON_DATASET_DIR.mkdir(parents=True, exist_ok=True)
|
| 25 |
+
|
| 26 |
+
JSON_DATASET_PATH = JSON_DATASET_DIR / f"train-{user_id}.json"
|
| 27 |
+
|
| 28 |
+
scheduler = CommitScheduler(
|
| 29 |
+
repo_id="authorship-obfuscation-demo-data",
|
| 30 |
+
repo_type="dataset",
|
| 31 |
+
folder_path=JSON_DATASET_DIR,
|
| 32 |
+
path_in_repo="data",
|
| 33 |
+
every=0.5
|
| 34 |
+
)
|
| 35 |
|
| 36 |
@spaces.GPU
|
| 37 |
def temp(text):
|
|
|
|
| 39 |
return response
|
| 40 |
|
| 41 |
def save_data(data):
|
| 42 |
+
with scheduler.lock:
|
| 43 |
+
with JSON_DATASET_PATH.open("a") as f:
|
| 44 |
+
json.dump(data, f)
|
| 45 |
+
f.write("\n")
|
| 46 |
+
scheduler.commit("Add new obfuscation data")
|
| 47 |
|
| 48 |
def save_feedback(feedback_rating, feedback_text):
|
| 49 |
global latest_obfuscation
|
|
|
|
| 100 |
|
| 101 |
# Save the obfuscation result
|
| 102 |
save_data(latest_obfuscation)
|
|
|
|
| 103 |
return response
|
| 104 |
|
| 105 |
def reset_sliders():
|