File size: 1,821 Bytes
1ab4362
8283b35
 
ed732ec
b2820ed
80f9f0f
b2820ed
7fa37a5
b2820ed
401411c
7fa37a5
3bbff8c
f1f799c
401411c
 
 
3bbff8c
e07cb10
 
5e96611
 
3c02d56
e0ccb39
8d81432
11e71f5
3659c6a
 
 
 
e07cb10
27001e3
 
 
 
 
 
5e96611
c9c4e90
 
95946b5
 
 
 
 
 
 
 
 
7b6d8e8
95946b5
 
 
 
 
27001e3
 
5e96611
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import gradio as gr
import os
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
import json

access_token = os.environ['ACCES_TOKEN']

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

tokenizer = AutoTokenizer.from_pretrained(
  "EkhiAzur/C1_Sailkapen_Demoa",
  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)

adibideak = json.load(open("./Adibideak.json", "r"))

def prozesatu(Testua, request: gr.Request):
    if Testua[-3:]=="...":
        Testua = prozesatu.adibideak[Testua]
    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"]}

def testua_itzuli(testua):
    if testua not in testua_itzuli.adibideak:
        return ""
    return testua_itzuli.adibideak[testua]
    
testua_itzuli.adibideak = adibideak
prozesatu.adibideak = adibideak
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)
    
  gr.Examples(list(adibideak.keys()), inputs=input, outputs=input, label="Adibideak:", fn=testua_itzuli, cache_examples=True)

demo.launch()