DanielRN commited on
Commit
655fe27
·
verified ·
1 Parent(s): 1430a0e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -44
app.py CHANGED
@@ -1,20 +1,19 @@
1
  import subprocess
2
  import sys
3
- import spacy
4
  import gradio as gr
5
  import re
6
  import os
7
  import random
8
  from fuzzywuzzy import fuzz
 
9
 
10
  # Instalar dependencias
11
- subprocess.check_call([sys.executable, "-m", "pip", "install", "spacy", "fuzzywuzzy", "python-levenshtein", "gradio"])
12
 
13
- # Descargar el modelo de lenguaje
14
- spacy.cli.download("es_core_news_sm")
15
-
16
- # Cargar el modelo de spaCy
17
- nlp = spacy.load("es_core_news_sm")
18
 
19
  # Diccionario de sinónimos para normalizar palabras clave
20
  sinonimos = {
@@ -250,40 +249,3 @@ def formatear_alojamiento(texto):
250
  print(f"Nombre extraído del primer bloque: {nombre}")
251
 
252
  return f"""🏠 Nombre: {nombre}
253
- 📍 Dirección: {direccion}
254
- 📞 Teléfono: {telefono}
255
- 🛏 Plazas: {plazas}
256
- 🐶 Política de mascotas: {mascotas}
257
- 📶 Wi-Fi: {wifi}
258
- 🛎 Servicios: {servicios}"""
259
-
260
- # Cargar el dataset
261
- dataset = cargar_dataset()
262
-
263
- # Interfaz con Gradio - Mantiene historial del chat
264
- with gr.Blocks(theme=gr.themes.Default()) as iface:
265
- gr.Markdown("### Bienvenido a Valer-IA, tu informante turístico virtual 🏡")
266
- gr.Markdown("Escribe una consulta sobre alojamientos, por ejemplo: '¿Qué alojamientos aceptan mascotas?' o 'Alojamiento con pileta y aire acondicionado'")
267
- chat_historial = gr.Textbox(label="Historial de chat", lines=15, interactive=False)
268
- pregunta_input = gr.Textbox(label="Escribe tu consulta:")
269
-
270
- def actualizar_chat(historial, nueva_pregunta):
271
- nueva_pregunta = nueva_pregunta.strip().capitalize()
272
- saludos = ["hola", "buenos días", "buenas tardes", "buenas noches", "qué tal", "hey", "saludos"]
273
-
274
- if nueva_pregunta.lower() in saludos:
275
- respuesta = "¡Hola! 😊 Soy Valer-IA, tu asistente turístico virtual. ¿En qué puedo ayudarte hoy?"
276
- elif nueva_pregunta.lower() in ["ver mas", "ver más"]:
277
- return ver_mas(historial), ""
278
- else:
279
- respuesta = responder_pregunta(nueva_pregunta, historial)
280
-
281
- return respuesta, ""
282
-
283
- preguntar_btn = gr.Button("Preguntar")
284
-
285
- # Se borra la pregunta después de ser contestada
286
- preguntar_btn.click(actualizar_chat, inputs=[chat_historial, pregunta_input], outputs=[chat_historial, pregunta_input])
287
-
288
- if __name__ == "__main__":
289
- iface.launch()
 
1
  import subprocess
2
  import sys
 
3
  import gradio as gr
4
  import re
5
  import os
6
  import random
7
  from fuzzywuzzy import fuzz
8
+ from transformers import TFAutoModelForSequenceClassification, AutoTokenizer
9
 
10
  # Instalar dependencias
11
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "transformers", "fuzzywuzzy", "python-levenshtein", "gradio"])
12
 
13
+ # Descargar el modelo y el tokenizador
14
+ model_name = "huggingface/distilbert-base-uncased-finetuned-sst-2-english"
15
+ model = TFAutoModelForSequenceClassification.from_pretrained(model_name)
16
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
 
17
 
18
  # Diccionario de sinónimos para normalizar palabras clave
19
  sinonimos = {
 
249
  print(f"Nombre extraído del primer bloque: {nombre}")
250
 
251
  return f"""🏠 Nombre: {nombre}