Spaces:
Runtime error
Runtime error
Commit
•
934a29a
1
Parent(s):
2e11d73
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,31 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
|
3 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
HF_TOKEN = os.getenv()
|
6 |
hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN,dataset_name="flagged_data")
|
@@ -14,6 +39,5 @@ gr.Interface.load("models/Amitesh007/tw-sentiment-finetuned",
|
|
14 |
title = title,
|
15 |
examples = examples,
|
16 |
allow_flagging="manual",
|
17 |
-
|
18 |
-
flagging_callback = hf_writer
|
19 |
).launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from gradio.components import IOComponent
|
3 |
+
|
4 |
+
from typing import List, Optional, Any
|
5 |
|
6 |
import os
|
7 |
+
import argilla as rg
|
8 |
+
|
9 |
+
class ArgillaLogger(FlaggingCallback):
|
10 |
+
def __init__(self, api_url, api_key):
|
11 |
+
rg.init(api_url=api_url, api_key=api_key)
|
12 |
+
|
13 |
+
def setup(self, components: List[IOComponent], flagging_dir: str):
|
14 |
+
pass
|
15 |
+
def flag(
|
16 |
+
self,
|
17 |
+
flag_data: List[Any],
|
18 |
+
flag_option: Optional[str] = ["incorrect","ambiguous"],
|
19 |
+
flag_index: Optional[int] = None,
|
20 |
+
username: Optional[str] = None,
|
21 |
+
) -> int:
|
22 |
+
text = flag_data[0]
|
23 |
+
inference = flag_data[1]
|
24 |
+
prediction = [(pred["label"], pred["confidence"]) for pred in inference["confidences"]]
|
25 |
+
rg.log(
|
26 |
+
name="sentiment_feedback",
|
27 |
+
records=rg.TextClassificationRecord(text=text, prediction=prediction)
|
28 |
+
)
|
29 |
|
30 |
HF_TOKEN = os.getenv()
|
31 |
hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN,dataset_name="flagged_data")
|
|
|
39 |
title = title,
|
40 |
examples = examples,
|
41 |
allow_flagging="manual",
|
42 |
+
flagging_callback=ArgillaLogger(api_url="https://dvilasuero-argilla-template-space.hf.space", api_key="team.apikey")
|
|
|
43 |
).launch()
|