# Aplicacion principal para cargar modelo, generar los prompts, y el la explicacion de los datos import streamlit as st import os import re import pandas as pd from supabase import create_client, Client from transformers import pipeline # funcion para extraccion de codigo del modelo def extract_code(llm_output): code_match = re.search(r"```python\n(.*?)\n```", llm_output, re.DOTALL) if code_match: return code_match.group(1) return None # funcion para prompts y ejemplo basico #prompt = "Generate a graph idea based on European fertility data." #output = generator(prompt, max_length=50, num_return_sequences=1)[0]['generated_text'] # Aqui vamos a aƱadir los prompts, comparativa entre paises, lo ideal es mas de uno, pero podriamos iniciar en un 1v1 con la metrica # Vamos a generar un codigo para luego ejecutarlo con un exec() y poder imprimir en Streamlit st.pyplot() def generate_graph_prompt(country1, country2, metric, start_year, end_year): prompt = f"""You have access to a database of European countries with data on {metric}, labor force participation, population, and their predictions for future years. Generate Python code using matplotlib to create a line graph showing the trend of {metric} for {country1} and {country2} from {start_year} to {end_year}. Also, provide a concise explanation of what this graph represents for an end user who might not be familiar with the data. """ return prompt # Ejemplo de como quedaria el prompt que recibiria el modelo #prompt = generate_graph_prompt("Germany", "France", "fertility rate", 2020, 2030) #Aqui van las credenciales, conectar las credenciales de Supabase en "Secrets" # conexion a supabase SUPABASE_URL = os.environ.get("SUPABASE_URL") SUPABASE_KEY = os.environ.get("SUPABASE_KEY") supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY) def load_data(): """fertility, geo data, labor, population y predictions """ try: response = supabase.from_("LabourForecast").select("*").execute() if response.error: st.error(f"Error fetching data: {response.error}") return pd.DataFrame() else: return pd.DataFrame(response.data) except Exception as e: st.error(f"An error occurred: {e}") return pd.DataFrame() # Pendiente las Keys, dependiendo del modelo que escojamos model_name = "google/flan-t5-small" # Probando modelos generator = pipeline("text-generation", model=model_name) # Inicio de Streamlit (hice lo basico, podemos mejorarla) st.title("_Europe GraphGen_ :blue[Graph generator] :flag-eu:") user_input = st.text_input("What graphics do you have in mind") generate_button = st.button("Generate") if generate_button and user_input: if not SUPABASE_URL or not SUPABASE_KEY: print("Error: Supabase URL and/or Key not found in environment variables.") else: try: response = supabase.table("LabourForecast").select("*").limit(1).execute() if response.error: print(f"Supabase connection test failed with error: {response.error}") else: print("Supabase connection test successful!") print("First row from 'your_test_table':", response.data) except Exception as e: print(f"An unexpected error occurred during Supabase connection test: {e}")