File size: 764 Bytes
8fdbc5b
 
f04c868
8fdbc5b
 
 
887a5ad
 
 
8fdbc5b
 
dcdc4b0
887a5ad
 
dcdc4b0
8fdbc5b
 
f04c868
8fdbc5b
 
 
 
88697a2
021c565
 
 
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
import gradio as gr
from fastai.text.all import *
from huggingface_hub import from_pretrained_fastai

repo_id = "almangad/entregable3" 
learner = from_pretrained_fastai(repo_id)

print("vocab:", learner.dls.vocab)
print("tipo:", type(learner.dls.vocab))

def predict_text(texto):
    pred_class, pred_idx, probs = learner.predict(texto)
    vocab = learner.dls.vocab[1]
    return {str(vocab[i]): float(probs[i]) for i in range(len(probs))}

demo = gr.Interface(
    fn=predict_text, 
    inputs=gr.Textbox(lines=3, placeholder="Text here..."),
    outputs=gr.Label(num_top_classes=6),
    examples=[
        ["im feeling quite sad and sorry for myself but ill snap out of it soon"],
        ["i am feeling grouchy"]
    ],
    cache_examples=False
)
demo.launch()