Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,47 +1,34 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
input_ids = encoded["input_ids"].to(device)
|
| 24 |
-
attention_mask = encoded["attention_mask"].to(device)
|
| 25 |
-
|
| 26 |
-
outputs = model.generate(
|
| 27 |
-
input_ids=input_ids,
|
| 28 |
-
attention_mask=attention_mask,
|
| 29 |
-
max_new_tokens=1024,
|
| 30 |
-
do_sample=False, # deterministic
|
| 31 |
-
repetition_penalty=1.08
|
| 32 |
-
)
|
| 33 |
-
|
| 34 |
-
decoded_output = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 35 |
-
return decoded_output
|
| 36 |
-
|
| 37 |
-
# Interface Gradio
|
| 38 |
iface = gr.Interface(
|
| 39 |
-
fn=
|
| 40 |
-
inputs=gr.Textbox(lines=
|
| 41 |
-
outputs=gr.Textbox(label="
|
| 42 |
-
title="HTML
|
| 43 |
-
description="
|
|
|
|
| 44 |
)
|
| 45 |
|
|
|
|
| 46 |
if __name__ == "__main__":
|
| 47 |
-
iface.launch(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import html2text
|
| 3 |
+
|
| 4 |
+
def html_para_markdown(html_input):
|
| 5 |
+
"""
|
| 6 |
+
Converte HTML para Markdown usando html2text.
|
| 7 |
+
|
| 8 |
+
:param html_input: String contendo o código HTML vindo da interface Gradio.
|
| 9 |
+
:return: String convertida para Markdown.
|
| 10 |
+
"""
|
| 11 |
+
if not html_input: # Verifica se a entrada está vazia
|
| 12 |
+
return "Por favor, insira algum código HTML."
|
| 13 |
+
|
| 14 |
+
try:
|
| 15 |
+
converter = html2text.HTML2Text()
|
| 16 |
+
converter.ignore_links = False # Mantém a configuração original (não ignorar links)
|
| 17 |
+
markdown_output = converter.handle(html_input)
|
| 18 |
+
return markdown_output
|
| 19 |
+
except Exception as e:
|
| 20 |
+
return f"Ocorreu um erro durante a conversão: {str(e)}"
|
| 21 |
+
|
| 22 |
+
# Cria a interface Gradio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
iface = gr.Interface(
|
| 24 |
+
fn=html_para_markdown, # Função a ser executada
|
| 25 |
+
inputs=gr.Textbox(lines=15, label="Insira o HTML aqui", placeholder="<html>...</html>"), # Componente de entrada: caixa de texto
|
| 26 |
+
outputs=gr.Textbox(lines=15, label="Markdown Resultante"), # Componente de saída: caixa de texto
|
| 27 |
+
title="Conversor HTML para Markdown", # Título da aplicação
|
| 28 |
+
description="Cole seu código HTML na caixa de texto à esquerda para vê-lo convertido em Markdown na caixa à direita.", # Descrição
|
| 29 |
+
allow_flagging='never' # Desabilita a opção de "flag"
|
| 30 |
)
|
| 31 |
|
| 32 |
+
# Lança a interface
|
| 33 |
if __name__ == "__main__":
|
| 34 |
+
iface.launch()
|