Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import (
|
| 3 |
AutoTokenizer,
|
| 4 |
-
AutoModelForSeq2SeqLM,
|
| 5 |
T5ForConditionalGeneration,
|
| 6 |
T5Tokenizer
|
| 7 |
)
|
|
@@ -25,16 +25,18 @@ def paraphrase_text(text):
|
|
| 25 |
inputs = st.session_state.paraphrase_tokenizer.encode(
|
| 26 |
text,
|
| 27 |
return_tensors="pt",
|
| 28 |
-
max_length=
|
| 29 |
truncation=True
|
| 30 |
)
|
| 31 |
|
| 32 |
outputs = st.session_state.paraphrase_model.generate(
|
| 33 |
inputs,
|
| 34 |
-
max_length=
|
|
|
|
| 35 |
do_sample=True,
|
| 36 |
-
temperature=0.
|
| 37 |
-
top_p=0.
|
|
|
|
| 38 |
)
|
| 39 |
|
| 40 |
return st.session_state.paraphrase_tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
@@ -43,21 +45,30 @@ def humanize_text(text):
|
|
| 43 |
"""
|
| 44 |
Humanize the input text using T5 model
|
| 45 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
input_ids = st.session_state.t5_tokenizer(
|
| 47 |
-
|
| 48 |
return_tensors="pt",
|
| 49 |
-
max_length=
|
| 50 |
truncation=True
|
| 51 |
).input_ids
|
| 52 |
|
| 53 |
outputs = st.session_state.t5_model.generate(
|
| 54 |
input_ids,
|
| 55 |
-
max_length=
|
|
|
|
| 56 |
do_sample=True,
|
| 57 |
-
temperature=0.
|
| 58 |
-
top_p=0.
|
| 59 |
-
num_beams=
|
| 60 |
-
no_repeat_ngram_size=
|
|
|
|
|
|
|
| 61 |
)
|
| 62 |
|
| 63 |
return st.session_state.t5_tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
@@ -65,24 +76,24 @@ def humanize_text(text):
|
|
| 65 |
# UI Components
|
| 66 |
st.set_page_config(page_title="Advanced Text Humanizer", page_icon="🤖")
|
| 67 |
|
| 68 |
-
st.title("🤖 → 🧑
|
| 69 |
st.markdown("""
|
| 70 |
-
|
| 71 |
-
|
| 72 |
""")
|
| 73 |
|
| 74 |
# Input area with expanded capabilities
|
| 75 |
input_text = st.text_area(
|
| 76 |
"Cole seu texto de robô aqui:",
|
| 77 |
height=150,
|
| 78 |
-
help="
|
| 79 |
)
|
| 80 |
|
| 81 |
# Advanced settings in sidebar
|
| 82 |
with st.sidebar:
|
| 83 |
-
st.header("
|
| 84 |
-
use_paraphrase = st.checkbox("
|
| 85 |
-
show_original = st.checkbox("
|
| 86 |
|
| 87 |
# Process button with error handling
|
| 88 |
if st.button("Humanizar", type="primary"):
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import (
|
| 3 |
AutoTokenizer,
|
| 4 |
+
AutoModelForSeq2SeqLM,
|
| 5 |
T5ForConditionalGeneration,
|
| 6 |
T5Tokenizer
|
| 7 |
)
|
|
|
|
| 25 |
inputs = st.session_state.paraphrase_tokenizer.encode(
|
| 26 |
text,
|
| 27 |
return_tensors="pt",
|
| 28 |
+
max_length=1024, # Aumentado para textos maiores
|
| 29 |
truncation=True
|
| 30 |
)
|
| 31 |
|
| 32 |
outputs = st.session_state.paraphrase_model.generate(
|
| 33 |
inputs,
|
| 34 |
+
max_length=1024,
|
| 35 |
+
min_length=len(text.split()) - 10, # Garante tamanho mínimo próximo ao original
|
| 36 |
do_sample=True,
|
| 37 |
+
temperature=0.3, # Reduzido para manter mais fiel ao original
|
| 38 |
+
top_p=0.95, # Aumentado para mais diversidade controlada
|
| 39 |
+
repetition_penalty=1.2 # Evita repetições
|
| 40 |
)
|
| 41 |
|
| 42 |
return st.session_state.paraphrase_tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
|
| 45 |
"""
|
| 46 |
Humanize the input text using T5 model
|
| 47 |
"""
|
| 48 |
+
# Modificado o prompt para enfatizar português e manter o contexto
|
| 49 |
+
prompt = (
|
| 50 |
+
f"reescreva o seguinte texto em português de forma mais natural e humana, "
|
| 51 |
+
f"mantendo todas as informações originais: {text}"
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
input_ids = st.session_state.t5_tokenizer(
|
| 55 |
+
prompt,
|
| 56 |
return_tensors="pt",
|
| 57 |
+
max_length=1024,
|
| 58 |
truncation=True
|
| 59 |
).input_ids
|
| 60 |
|
| 61 |
outputs = st.session_state.t5_model.generate(
|
| 62 |
input_ids,
|
| 63 |
+
max_length=1024,
|
| 64 |
+
min_length=len(text.split()) - 10, # Garante tamanho mínimo próximo ao original
|
| 65 |
do_sample=True,
|
| 66 |
+
temperature=0.3, # Reduzido para manter mais fiel ao original
|
| 67 |
+
top_p=0.95, # Aumentado para mais diversidade controlada
|
| 68 |
+
num_beams=5, # Aumentado para melhor qualidade
|
| 69 |
+
no_repeat_ngram_size=3, # Evita repetições de trigramas
|
| 70 |
+
repetition_penalty=1.2, # Penalidade para repetições
|
| 71 |
+
length_penalty=1.0 # Incentiva manter o tamanho similar
|
| 72 |
)
|
| 73 |
|
| 74 |
return st.session_state.t5_tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
|
| 76 |
# UI Components
|
| 77 |
st.set_page_config(page_title="Advanced Text Humanizer", page_icon="🤖")
|
| 78 |
|
| 79 |
+
st.title("🤖 → 🧑 Humanizador de Texto Avançado")
|
| 80 |
st.markdown("""
|
| 81 |
+
Este aplicativo transforma textos robotizados em linguagem mais natural e humana,
|
| 82 |
+
mantendo todas as informações originais.
|
| 83 |
""")
|
| 84 |
|
| 85 |
# Input area with expanded capabilities
|
| 86 |
input_text = st.text_area(
|
| 87 |
"Cole seu texto de robô aqui:",
|
| 88 |
height=150,
|
| 89 |
+
help="Cole seu texto aqui para transformá-lo em uma versão mais natural e humana."
|
| 90 |
)
|
| 91 |
|
| 92 |
# Advanced settings in sidebar
|
| 93 |
with st.sidebar:
|
| 94 |
+
st.header("Configurações Avançadas")
|
| 95 |
+
use_paraphrase = st.checkbox("Ativar Paráfrase", value=True)
|
| 96 |
+
show_original = st.checkbox("Mostrar Texto Original", value=False)
|
| 97 |
|
| 98 |
# Process button with error handling
|
| 99 |
if st.button("Humanizar", type="primary"):
|