manuelcozar55 commited on
Commit
4d16851
verified
1 Parent(s): 9793f38

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -13
app.py CHANGED
@@ -1,19 +1,24 @@
1
  import streamlit as st
2
  from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM, AutoConfig, AutoModelForSequenceClassification
3
- from langchain.llms import HuggingFacePipeline
4
  from langchain.prompts import PromptTemplate
5
  from langchain.chains import LLMChain
6
- from langchain.embeddings.huggingface import HuggingFaceEmbeddings
7
  from PyPDF2 import PdfReader
8
  from docx import Document
9
  import csv
10
  import json
11
  import torch
12
- from langchain.vectorstores import FAISS
13
  from langchain.text_splitter import RecursiveCharacterTextSplitter
 
 
 
 
 
14
 
15
  # Configurar modelo y tokenizador
16
- model_name = 'mistralai/Mistral-7B-Instruct-v0.3'
17
  model_config = AutoConfig.from_pretrained(model_name)
18
  tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
19
  tokenizer.pad_token = tokenizer.eos_token
@@ -173,17 +178,20 @@ def main():
173
  document_text = handle_uploaded_file(uploaded_file)
174
  if operation == "Traducir":
175
  target_language = st.selectbox("Selecciona el idioma de traducci贸n", ["espa帽ol", "ingl茅s", "franc茅s", "alem谩n"])
176
- bot_response = translate(document_text, target_language)
 
 
177
  elif operation == "Resumir":
178
  summary_length = st.selectbox("Selecciona la longitud del resumen", ["corto", "medio", "largo"])
179
- if summary_length == "corto":
180
- length = "de aproximadamente 50 palabras"
181
- elif summary_length == "medio":
182
- length = "de aproximadamente 100 palabras"
183
- elif summary_length == "largo":
184
- length = "de aproximadamente 500 palabras"
185
- bot_response = summarize(document_text, length)
186
- st.write(f"**Assistant:** {bot_response}")
 
187
 
188
  if __name__ == "__main__":
189
  main()
 
1
  import streamlit as st
2
  from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM, AutoConfig, AutoModelForSequenceClassification
3
+ from langchain_community.llms import HuggingFacePipeline
4
  from langchain.prompts import PromptTemplate
5
  from langchain.chains import LLMChain
6
+ from langchain_community.embeddings import HuggingFaceEmbeddings
7
  from PyPDF2 import PdfReader
8
  from docx import Document
9
  import csv
10
  import json
11
  import torch
12
+ from langchain_community.vectorstores import FAISS
13
  from langchain.text_splitter import RecursiveCharacterTextSplitter
14
+ from huggingface_hub import login
15
+
16
+ # Autenticaci贸n en Hugging Face
17
+ huggingface_token = st.secrets["HUGGINGFACE_TOKEN"]
18
+ login(huggingface_token)
19
 
20
  # Configurar modelo y tokenizador
21
+ model_name = 'mistralai/Mistral-7B-Instruct-v0.1'
22
  model_config = AutoConfig.from_pretrained(model_name)
23
  tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
24
  tokenizer.pad_token = tokenizer.eos_token
 
178
  document_text = handle_uploaded_file(uploaded_file)
179
  if operation == "Traducir":
180
  target_language = st.selectbox("Selecciona el idioma de traducci贸n", ["espa帽ol", "ingl茅s", "franc茅s", "alem谩n"])
181
+ if target_language:
182
+ bot_response = translate(document_text, target_language)
183
+ st.write(f"**Assistant:** {bot_response}")
184
  elif operation == "Resumir":
185
  summary_length = st.selectbox("Selecciona la longitud del resumen", ["corto", "medio", "largo"])
186
+ if summary_length:
187
+ if summary_length == "corto":
188
+ length = "de aproximadamente 50 palabras"
189
+ elif summary_length == "medio":
190
+ length = "de aproximadamente 100 palabras"
191
+ elif summary_length == "largo":
192
+ length = "de aproximadamente 500 palabras"
193
+ bot_response = summarize(document_text, length)
194
+ st.write(f"**Assistant:** {bot_response}")
195
 
196
  if __name__ == "__main__":
197
  main()