Spaces:
Runtime error
Runtime error
File size: 1,893 Bytes
dc4cc7d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
import os
import gradio as gr
from gradio import FlaggingCallback
from gradio.components import IOComponent
from datasets import load_dataset
from typing import List, Optional, Any
import argilla as rg
import os
def load_data():
ds = load_dataset("merve/turkish_instructions", split="train", streaming=True)
sample = next(iter(ds))
return sample
def create_record(sample, feedback):
status = "Validated" if feedback == "DoΔru" else "Default"
#sample = next(iter(ds))
fields = {
"talimat": sample["talimat"],
"input": sample["giriΕ"],
"response": sample["Γ§Δ±ktΔ±"]
}
# the label will come from the flag object in Gradio
label = "True"
record = rg.TextClassificationRecord(
inputs=fields,
annotation=label,
status=status,
metadata={"feedback": feedback}
)
print(record)
return record
class ArgillaLogger(FlaggingCallback):
def __init__(self, api_url, api_key, dataset_name):
rg.init(api_url=api_url, api_key=api_key)
self.dataset_name = dataset_name
def setup(self, components: List[IOComponent], flagging_dir: str):
pass
def flag(
self,
flag_data: List[Any],
flag_option: Optional[str] = None,
flag_index: Optional[int] = None,
username: Optional[str] = None,
) -> int:
text = flag_data[0]
inference = flag_data[1]
rg.log(name=self.dataset_name, records=create_record(text, flag_option))
gr.Interface(
title = "ALPACA Veriseti DΓΌzeltme ArayΓΌzΓΌ",
description = "",
allow_flagging="manual",
flagging_callback=ArgillaLogger(
api_url="https://sandbox.argilla.io",
api_key=os.getenv("TEAM_API_KEY"),
dataset_name="alpaca-flags"
),
flagging_options=["DoΔru", "YanlΔ±Ε", "Belirsiz"]
).launch() |