Spaces:
Runtime error
Runtime error
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(idx): | |
df = load_dataset("merve/turkish_instructions", split="train").to_pandas() | |
sample = df.iloc[int(idx)] | |
instruction = sample["talimat"] | |
input_sample = sample["giriΕ"] | |
response = sample["Γ§Δ±ktΔ±"] | |
return instruction, input_sample, response | |
def create_record(instruction, inpu_sample, response, feedback): | |
status = "Validated" if feedback == "DoΔru" else "Default" | |
fields = { | |
"talimat": instruction, | |
"input": input_sample, | |
"response": response | |
} | |
# 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( | |
load_data, | |
title = "ALPACA Veriseti DΓΌzeltme ArayΓΌzΓΌ", | |
description = "Bir satΔ±r sayΔ±sΔ± verip ΓΆrnek alΔ±n.", | |
allow_flagging="manual", | |
flagging_callback=ArgillaLogger( | |
api_url="https://sandbox.argilla.io", | |
api_key=os.getenv("API_KEY"), | |
dataset_name="alpaca-flags" | |
), | |
inputs=["text"], | |
outputs=["text", "text", "text"], | |
flagging_options=["DoΔru", "YanlΔ±Ε", "Belirsiz"] | |
).launch() |