Spaces:
Running
Running
App.py running locally (w/ gemma3:12b from Ollama)
#3
by
Xilena
- opened
app.py
CHANGED
@@ -8,10 +8,10 @@ import re
|
|
8 |
import pandas as pd # type: ignore
|
9 |
from dotenv import load_dotenv # type: ignore # Para cambios locales
|
10 |
from supabase import create_client, Client # type: ignore
|
11 |
-
from transformers import pipeline
|
12 |
|
13 |
from pandasai import SmartDataframe # type: ignore
|
14 |
-
from pandasai.llm.
|
15 |
|
16 |
# ---------------------------------------------------------------------------------
|
17 |
# Funciones auxiliares
|
@@ -94,6 +94,36 @@ data = load_data("labor")
|
|
94 |
# population_data = load_data("population")
|
95 |
# predictions_data = load_data("predictions")
|
96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
# ---------------------------------------------------------------------------------
|
98 |
# Inicializar modelo LLM
|
99 |
# ---------------------------------------------------------------------------------
|
@@ -106,11 +136,16 @@ data = load_data("labor")
|
|
106 |
# Inicializar PandasAI con StarCoder
|
107 |
# ---------------------------------------------------------------------------------
|
108 |
|
109 |
-
# Definir el modelo StarCoder desde Hugging Face
|
110 |
-
huggingface_token = os.getenv("HUGGINGFACE_TOKEN")
|
111 |
-
llm = Starcoder(api_token=huggingface_token)
|
|
|
|
|
|
|
|
|
|
|
112 |
|
113 |
-
sdf = SmartDataframe(data, config={"llm":
|
114 |
|
115 |
# ---------------------------------------------------------------------------------
|
116 |
# Configuración de la app en Streamlit
|
@@ -123,28 +158,16 @@ st.title("_Europe GraphGen_ :blue[Graph generator] :flag-eu:")
|
|
123 |
user_input = st.text_input("What graphics do you have in mind")
|
124 |
generate_button = st.button("Generate")
|
125 |
|
126 |
-
#
|
127 |
if generate_button and user_input:
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
# st.info("Attempted to load data. Check for any error messages above.")
|
137 |
-
|
138 |
-
# Procesar el input del usuario con PandasAI
|
139 |
-
if generate_button and user_input:
|
140 |
-
st.dataframe(data.head())
|
141 |
-
|
142 |
-
with st.spinner('Generating answer...'):
|
143 |
-
try:
|
144 |
-
answer = sdf.chat(user_input)
|
145 |
-
st.write(answer)
|
146 |
-
except Exception as e:
|
147 |
-
st.error(f"Error generating answer: {e}")
|
148 |
|
149 |
|
150 |
# TODO: Output estructurado si vemos que es necesario.
|
|
|
8 |
import pandas as pd # type: ignore
|
9 |
from dotenv import load_dotenv # type: ignore # Para cambios locales
|
10 |
from supabase import create_client, Client # type: ignore
|
11 |
+
# from transformers import pipeline
|
12 |
|
13 |
from pandasai import SmartDataframe # type: ignore
|
14 |
+
from pandasai.llm.local_llm import LocalLLM
|
15 |
|
16 |
# ---------------------------------------------------------------------------------
|
17 |
# Funciones auxiliares
|
|
|
94 |
# population_data = load_data("population")
|
95 |
# predictions_data = load_data("predictions")
|
96 |
|
97 |
+
"""
|
98 |
+
# Ej:
|
99 |
+
# import os
|
100 |
+
# import pandas as pd
|
101 |
+
# from pandasai import SmartDatalake
|
102 |
+
|
103 |
+
# employees_data = {
|
104 |
+
# 'EmployeeID': [1, 2, 3, 4, 5],
|
105 |
+
# 'Name': ['John', 'Emma', 'Liam', 'Olivia', 'William'],
|
106 |
+
# 'Department': ['HR', 'Sales', 'IT', 'Marketing', 'Finance']
|
107 |
+
# }
|
108 |
+
|
109 |
+
# salaries_data = {
|
110 |
+
# 'EmployeeID': [1, 2, 3, 4, 5],
|
111 |
+
# 'Salary': [5000, 6000, 4500, 7000, 5500]
|
112 |
+
# }
|
113 |
+
|
114 |
+
# employees_df = pd.DataFrame(employees_data)
|
115 |
+
# salaries_df = pd.DataFrame(salaries_data)
|
116 |
+
|
117 |
+
# # By default, unless you choose a different LLM, it will use BambooLLM.
|
118 |
+
# # You can get your free API key signing up at https://pandabi.ai (you can also configure it in your .env file)
|
119 |
+
# os.environ["PANDASAI_API_KEY"] = "YOUR_API_KEY"
|
120 |
+
|
121 |
+
# lake = SmartDatalake([employees_df, salaries_df])
|
122 |
+
# lake.chat("Who gets paid the most?")
|
123 |
+
# # Output: Olivia gets paid the most
|
124 |
+
|
125 |
+
"""
|
126 |
+
|
127 |
# ---------------------------------------------------------------------------------
|
128 |
# Inicializar modelo LLM
|
129 |
# ---------------------------------------------------------------------------------
|
|
|
136 |
# Inicializar PandasAI con StarCoder
|
137 |
# ---------------------------------------------------------------------------------
|
138 |
|
139 |
+
# # Definir el modelo StarCoder desde Hugging Face
|
140 |
+
# huggingface_token = os.getenv("HUGGINGFACE_TOKEN")
|
141 |
+
# llm = Starcoder(api_token=huggingface_token)
|
142 |
+
|
143 |
+
ollama_llm = LocalLLM(api_base="http://localhost:11434/v1",
|
144 |
+
model="gemma3:12b",
|
145 |
+
temperature=0.1,
|
146 |
+
max_tokens=8000)
|
147 |
|
148 |
+
sdf = SmartDataframe(data, config={"llm": ollama_llm}) # DataFrame PandasAI-ready.
|
149 |
|
150 |
# ---------------------------------------------------------------------------------
|
151 |
# Configuración de la app en Streamlit
|
|
|
158 |
user_input = st.text_input("What graphics do you have in mind")
|
159 |
generate_button = st.button("Generate")
|
160 |
|
161 |
+
# Procesar el input del usuario con PandasAI
|
162 |
if generate_button and user_input:
|
163 |
+
st.dataframe(data.head())
|
164 |
+
|
165 |
+
with st.spinner('Generating answer...'):
|
166 |
+
try:
|
167 |
+
answer = sdf.chat(user_input)
|
168 |
+
st.write(answer)
|
169 |
+
except Exception as e:
|
170 |
+
st.error(f"Error generating answer: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
|
172 |
|
173 |
# TODO: Output estructurado si vemos que es necesario.
|