Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,38 @@
|
|
| 1 |
-
import os
|
| 2 |
import gradio as gr
|
| 3 |
-
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
model = AutoModelForCausalLM.from_pretrained(model_id, use_auth_token=HUGGINGFACE_TOKEN, trust_remote_code=True)
|
| 12 |
|
| 13 |
-
def
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
iface = gr.Interface(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
# Executar o app
|
| 23 |
if __name__ == "__main__":
|
| 24 |
iface.launch()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 4 |
|
| 5 |
+
checkpoint = "jinaai/reader-lm-0.5b"
|
| 6 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 7 |
|
| 8 |
+
# Carrega modelo e tokenizer
|
| 9 |
+
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
| 10 |
+
model = AutoModelForCausalLM.from_pretrained(checkpoint).to(device)
|
|
|
|
| 11 |
|
| 12 |
+
def process_html(html_content):
|
| 13 |
+
messages = [{"role": "user", "content": html_content}]
|
| 14 |
+
input_text = tokenizer.apply_chat_template(messages, tokenize=False)
|
| 15 |
+
|
| 16 |
+
inputs = tokenizer.encode(input_text, return_tensors="pt").to(device)
|
| 17 |
+
outputs = model.generate(
|
| 18 |
+
inputs,
|
| 19 |
+
max_new_tokens=1024,
|
| 20 |
+
temperature=0,
|
| 21 |
+
do_sample=False,
|
| 22 |
+
repetition_penalty=1.08
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
decoded_output = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 26 |
+
return decoded_output
|
| 27 |
|
| 28 |
+
# Interface Gradio
|
| 29 |
+
iface = gr.Interface(
|
| 30 |
+
fn=process_html,
|
| 31 |
+
inputs=gr.Textbox(lines=10, placeholder="Insira o conteúdo HTML aqui...", label="HTML"),
|
| 32 |
+
outputs=gr.Textbox(label="Resposta do modelo"),
|
| 33 |
+
title="HTML Reader (jinaai/reader-lm-0.5b)",
|
| 34 |
+
description="Insira um conteúdo HTML e veja como o modelo interpreta o conteúdo."
|
| 35 |
+
)
|
| 36 |
|
|
|
|
| 37 |
if __name__ == "__main__":
|
| 38 |
iface.launch()
|