File size: 1,331 Bytes
1ab4362
8283b35
 
b2820ed
80f9f0f
b2820ed
3bbff8c
b2820ed
401411c
3bbff8c
 
f1f799c
401411c
 
 
3bbff8c
e07cb10
 
3c02d56
11e71f5
3659c6a
 
 
 
e07cb10
c9c4e90
 
95946b5
 
 
 
 
 
 
 
 
7b6d8e8
95946b5
 
 
 
 
 
 
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
import gradio as gr
import os
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification

access_token = os.environ['ACCES_TOKEN']

model = AutoModelForSequenceClassification.from_pretrained("EkhiAzur/RoBERTA_3", token=access_token)

tokenizer = AutoTokenizer.from_pretrained(
  "EkhiAzur/RoBERTA_3",
  token = access_token,
  use_fast=True,
  add_prefix_space=True,
)

classifier = pipeline("text-classification", tokenizer=tokenizer, model=model, max_length=512,
                padding=True, truncation=True, batch_size=1)

def prozesatu(Testua, request: gr.Request):
    prediction = prozesatu.classifier(Testua)[0]
    if prediction["label"]=="GAI":
        return {"Gai":prediction["score"], "Ez gai": 1-prediction["score"]}
    else:
        return {"Gai":1-prediction["score"], "Ez gai": prediction["score"]}

prozesatu.classifier = classifier

def ezabatu(Testua):
  return ""

with gr.Blocks() as demo:
  with gr.Row():
    with gr.Column():
      input = gr.Textbox(label="Testua")
      with gr.Row():
        bidali_btn = gr.Button("Bidali")
        ezabatu_btn = gr.Button("Ezabatu")
    
    label = gr.Label(num_top_classes=2, label="C1 maila")
  
    
  bidali_btn.click(fn=prozesatu, inputs=input, outputs=label)
  ezabatu_btn.click(fn=ezabatu, inputs=input, outputs=input)
demo.launch()