Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -59,9 +59,8 @@ Asegúrese de que la traducción sea precisa y conserve el significado original
|
|
59 |
'''
|
60 |
|
61 |
formatted_prompt = template.replace("{TEXT}", text).replace("{LANGUAGE}", target_language)
|
62 |
-
|
63 |
-
|
64 |
-
translated_text = outputs.content
|
65 |
|
66 |
return translated_text
|
67 |
|
@@ -74,9 +73,8 @@ def summarize(text, length):
|
|
74 |
Asegúrese de que el resumen sea conciso y conserve el significado original del documento.
|
75 |
'''
|
76 |
|
77 |
-
|
78 |
-
|
79 |
-
summarized_text = outputs.content
|
80 |
|
81 |
return summarized_text
|
82 |
|
@@ -106,53 +104,60 @@ def handle_uploaded_file(uploaded_file):
|
|
106 |
except Exception as e:
|
107 |
return str(e)
|
108 |
|
109 |
-
|
110 |
-
st.
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
if
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
if
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
'''
|
60 |
|
61 |
formatted_prompt = template.replace("{TEXT}", text).replace("{LANGUAGE}", target_language)
|
62 |
+
response = llm_engine_hf.invoke(formatted_prompt)
|
63 |
+
translated_text = response['generated_text']
|
|
|
64 |
|
65 |
return translated_text
|
66 |
|
|
|
73 |
Asegúrese de que el resumen sea conciso y conserve el significado original del documento.
|
74 |
'''
|
75 |
|
76 |
+
response = llm_engine_hf.invoke(template)
|
77 |
+
summarized_text = response['generated_text']
|
|
|
78 |
|
79 |
return summarized_text
|
80 |
|
|
|
104 |
except Exception as e:
|
105 |
return str(e)
|
106 |
|
107 |
+
def main():
|
108 |
+
st.title("LexAIcon")
|
109 |
+
st.write("Puedes conversar con este chatbot basado en Mistral7B-Instruct y subir archivos para que el chatbot los procese.")
|
110 |
+
|
111 |
+
if "generated" not in st.session_state:
|
112 |
+
st.session_state["generated"] = []
|
113 |
+
if "past" not in st.session_state:
|
114 |
+
st.session_state["past"] = []
|
115 |
+
|
116 |
+
# Entrada del usuario
|
117 |
+
user_input = st.text_input("Tú: ", "")
|
118 |
+
|
119 |
+
# Botones de Resumir, Traducir y Explicar
|
120 |
+
operation = st.radio("Selecciona una operación", ["Resumir", "Traducir", "Explicar"])
|
121 |
+
|
122 |
+
target_language = None
|
123 |
+
summary_length = None
|
124 |
+
|
125 |
+
if operation == "Traducir":
|
126 |
+
target_language = st.selectbox("Selecciona el idioma de traducción", ["español", "inglés", "francés", "alemán"])
|
127 |
+
|
128 |
+
if operation == "Resumir":
|
129 |
+
summary_length = st.selectbox("Selecciona la longitud del resumen", ["corto", "medio", "largo"])
|
130 |
+
|
131 |
+
# Manejo de archivos subidos
|
132 |
+
uploaded_files = st.file_uploader("Sube un archivo", type=["txt", "pdf", "docx", "csv", "json"], accept_multiple_files=True)
|
133 |
+
|
134 |
+
if st.button("Enviar"):
|
135 |
+
if user_input:
|
136 |
+
response = llm_engine_hf.invoke(user_input)
|
137 |
+
st.session_state.generated.append({"user": user_input, "bot": response['generated_text']})
|
138 |
+
|
139 |
+
if st.button("Ejecutar"):
|
140 |
+
if uploaded_files:
|
141 |
+
for uploaded_file in uploaded_files:
|
142 |
+
file_content = handle_uploaded_file(uploaded_file)
|
143 |
+
if operation == "Resumir":
|
144 |
+
if summary_length == "corto":
|
145 |
+
length = "de aproximadamente 50 palabras"
|
146 |
+
elif summary_length == "medio":
|
147 |
+
length = "de aproximadamente 100 palabras"
|
148 |
+
elif summary_length == "largo":
|
149 |
+
length = "de aproximadamente 500 palabras"
|
150 |
+
result = summarize(file_content, length)
|
151 |
+
elif operation == "Traducir":
|
152 |
+
result = translate(file_content, target_language)
|
153 |
+
elif operation == "Explicar":
|
154 |
+
result = classify_text(file_content)
|
155 |
+
st.write(result)
|
156 |
+
|
157 |
+
if st.session_state.get("generated"):
|
158 |
+
for chat in st.session_state["generated"]:
|
159 |
+
st.write(f"Tú: {chat['user']}")
|
160 |
+
st.write(f"Chatbot: {chat['bot']}")
|
161 |
+
|
162 |
+
if __name__ == "__main__":
|
163 |
+
main()
|