Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,24 +13,15 @@ from langchain.text_splitter import RecursiveCharacterTextSplitter
|
|
| 13 |
from langchain.embeddings import HuggingFaceEmbeddings
|
| 14 |
from langchain.vectorstores import FAISS
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
# Realizar el inicio de sesi贸n de Hugging Face solo si el token est谩 disponible
|
| 19 |
-
if huggingface_token:
|
| 20 |
-
login(token=huggingface_token)
|
| 21 |
-
|
| 22 |
-
# Configuraci贸n del modelo de generaci贸n de texto
|
| 23 |
@st.cache_resource
|
| 24 |
-
def
|
| 25 |
-
llm = HuggingFaceEndpoint(
|
| 26 |
-
repo_id="mistralai/Mistral-7B-Instruct-v0.3",
|
| 27 |
-
task="text-generation"
|
| 28 |
-
)
|
| 29 |
-
llm_engine_hf = ChatHuggingFace(llm=llm)
|
| 30 |
tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.3")
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
| 34 |
|
| 35 |
# Configuraci贸n del modelo de clasificaci贸n
|
| 36 |
@st.cache_resource
|
|
@@ -89,8 +80,8 @@ Aseg煤rese de que la traducci贸n sea precisa y conserve el significado original
|
|
| 89 |
'''
|
| 90 |
|
| 91 |
formatted_prompt = template.replace("{TEXT}", text).replace("{LANGUAGE}", target_language)
|
| 92 |
-
response =
|
| 93 |
-
translated_text = response
|
| 94 |
|
| 95 |
return translated_text
|
| 96 |
|
|
@@ -103,8 +94,8 @@ def summarize(text, length):
|
|
| 103 |
Aseg煤rese de que el resumen sea conciso y conserve el significado original del documento.
|
| 104 |
'''
|
| 105 |
|
| 106 |
-
response =
|
| 107 |
-
summarized_text = response
|
| 108 |
|
| 109 |
return summarized_text
|
| 110 |
|
|
@@ -135,7 +126,6 @@ def handle_uploaded_file(uploaded_file):
|
|
| 135 |
return str(e)
|
| 136 |
|
| 137 |
def main():
|
| 138 |
-
st.image("./icon.jpg", width=100)
|
| 139 |
st.title("LexAIcon")
|
| 140 |
st.write("Puedes conversar con este chatbot basado en Mistral7B-Instruct y subir archivos para que el chatbot los procese.")
|
| 141 |
|
|
@@ -171,8 +161,8 @@ def main():
|
|
| 171 |
search_docs = vector_store.similarity_search(prompt)
|
| 172 |
context = " ".join([doc.page_content for doc in search_docs])
|
| 173 |
prompt_with_context = f"Contexto: {context}\n\nPregunta: {prompt}"
|
| 174 |
-
response =
|
| 175 |
-
msg = response
|
| 176 |
|
| 177 |
elif operation == "Resumir":
|
| 178 |
if summary_length == "corto":
|
|
@@ -187,7 +177,8 @@ def main():
|
|
| 187 |
msg = translate(prompt, target_language)
|
| 188 |
|
| 189 |
else:
|
| 190 |
-
|
|
|
|
| 191 |
|
| 192 |
st.session_state.messages.append({"role": "assistant", "content": msg})
|
| 193 |
st.chat_message("assistant").write(msg)
|
|
|
|
| 13 |
from langchain.embeddings import HuggingFaceEmbeddings
|
| 14 |
from langchain.vectorstores import FAISS
|
| 15 |
|
| 16 |
+
# Cargar el modelo y el pipeline de Hugging Face
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
@st.cache_resource
|
| 18 |
+
def load_pipeline():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.3")
|
| 20 |
+
model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.3")
|
| 21 |
+
text_gen_pipeline = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 22 |
+
return text_gen_pipeline
|
| 23 |
|
| 24 |
+
text_gen_pipeline = load_pipeline()
|
| 25 |
|
| 26 |
# Configuraci贸n del modelo de clasificaci贸n
|
| 27 |
@st.cache_resource
|
|
|
|
| 80 |
'''
|
| 81 |
|
| 82 |
formatted_prompt = template.replace("{TEXT}", text).replace("{LANGUAGE}", target_language)
|
| 83 |
+
response = text_gen_pipeline(formatted_prompt, max_length=512)
|
| 84 |
+
translated_text = response[0]['generated_text']
|
| 85 |
|
| 86 |
return translated_text
|
| 87 |
|
|
|
|
| 94 |
Aseg煤rese de que el resumen sea conciso y conserve el significado original del documento.
|
| 95 |
'''
|
| 96 |
|
| 97 |
+
response = text_gen_pipeline(template, max_length=512)
|
| 98 |
+
summarized_text = response[0]['generated_text']
|
| 99 |
|
| 100 |
return summarized_text
|
| 101 |
|
|
|
|
| 126 |
return str(e)
|
| 127 |
|
| 128 |
def main():
|
|
|
|
| 129 |
st.title("LexAIcon")
|
| 130 |
st.write("Puedes conversar con este chatbot basado en Mistral7B-Instruct y subir archivos para que el chatbot los procese.")
|
| 131 |
|
|
|
|
| 161 |
search_docs = vector_store.similarity_search(prompt)
|
| 162 |
context = " ".join([doc.page_content for doc in search_docs])
|
| 163 |
prompt_with_context = f"Contexto: {context}\n\nPregunta: {prompt}"
|
| 164 |
+
response = text_gen_pipeline(prompt_with_context, max_length=512)
|
| 165 |
+
msg = response[0]['generated_text']
|
| 166 |
|
| 167 |
elif operation == "Resumir":
|
| 168 |
if summary_length == "corto":
|
|
|
|
| 177 |
msg = translate(prompt, target_language)
|
| 178 |
|
| 179 |
else:
|
| 180 |
+
response = text_gen_pipeline(prompt, max_length=512)
|
| 181 |
+
msg = response[0]['generated_text']
|
| 182 |
|
| 183 |
st.session_state.messages.append({"role": "assistant", "content": msg})
|
| 184 |
st.chat_message("assistant").write(msg)
|