alexacido commited on
Commit
f4e2922
verified
1 Parent(s): aefc36c

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +16 -7
  2. app.py +54 -0
  3. requirements.txt +4 -0
README.md CHANGED
@@ -1,14 +1,23 @@
 
1
  ---
2
- title: Asistente 8
3
- emoji: 馃弮
4
- colorFrom: yellow
5
- colorTo: green
6
  sdk: gradio
7
- sdk_version: 5.33.0
8
  app_file: app.py
9
  pinned: false
10
  license: mit
11
- short_description: Analizador de .cvs
12
  ---
13
 
14
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
1
+
2
  ---
3
+ title: CSV Q&A con LLM
4
+ emoji: 馃搳
5
+ colorFrom: indigo
6
+ colorTo: blue
7
  sdk: gradio
8
+ sdk_version: 4.21.0
9
  app_file: app.py
10
  pinned: false
11
  license: mit
 
12
  ---
13
 
14
+ # CSV Q&A con LLM
15
+
16
+ Este Space permite:
17
+ - Subir un archivo `.csv`
18
+ - Hacer preguntas en lenguaje natural usando el modelo `mistralai/Mistral-7B-Instruct-v0.1` desde Hugging Face
19
+
20
+ ## Uso
21
+ 1. Sube tu archivo `.csv`.
22
+ 2. Introduce tu token de Hugging Face con permisos de inferencia.
23
+ 3. Escribe preguntas como "驴Cu谩l es el promedio de la columna ingresos?".
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import os
3
+ os.system("pip install pandasai==1.6.2 pandas==2.2.2 gradio==4.21.0")
4
+
5
+ import gradio as gr
6
+ import pandas as pd
7
+ from pandasai import SmartDataframe
8
+ from pandasai.llm import OpenSourceLLM
9
+
10
+ df_global = None
11
+
12
+ def cargar_csv(file):
13
+ global df_global
14
+ try:
15
+ df_global = pd.read_csv(file.name)
16
+ return f"Archivo cargado con 茅xito. Filas: {len(df_global)}, Columnas: {len(df_global.columns)}"
17
+ except Exception as e:
18
+ return f"Error al cargar el archivo: {str(e)}"
19
+
20
+ def responder_pregunta(pregunta, token):
21
+ global df_global
22
+ if df_global is None:
23
+ return "Primero debes cargar un archivo CSV."
24
+
25
+ try:
26
+ llm = OpenSourceLLM(
27
+ model="mistralai/Mistral-7B-Instruct-v0.1",
28
+ api_token=token
29
+ )
30
+ sdf = SmartDataframe(df_global, config={"llm": llm})
31
+ respuesta = sdf.chat(pregunta)
32
+ return respuesta
33
+ except Exception as e:
34
+ return f"Ocurri贸 un error: {str(e)}"
35
+
36
+ with gr.Blocks() as demo:
37
+ gr.Markdown("# Analizador CSV con Preguntas en Lenguaje Natural")
38
+
39
+ with gr.Row():
40
+ archivo = gr.File(label="Sube tu archivo CSV", file_types=[".csv"])
41
+ salida_carga = gr.Textbox(label="Resultado de carga")
42
+ boton_carga = gr.Button("Cargar CSV")
43
+
44
+ with gr.Row():
45
+ pregunta = gr.Textbox(label="Escribe tu pregunta sobre los datos")
46
+ token = gr.Textbox(label="Token de Hugging Face (requerido)", type="password")
47
+ salida_respuesta = gr.Textbox(label="Respuesta")
48
+ boton_pregunta = gr.Button("Responder")
49
+
50
+ boton_carga.click(cargar_csv, inputs=[archivo], outputs=[salida_carga])
51
+ boton_pregunta.click(responder_pregunta, inputs=[pregunta, token], outputs=[salida_respuesta])
52
+
53
+ if __name__ == "__main__":
54
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+
2
+ gradio==4.21.0
3
+ pandas==2.2.2
4
+ pandasai==1.6.2