Spaces:
Sleeping
Sleeping
Uploading new App version (#10)
Browse files- Uploading new App version (c4035fd99ba4319a2dfa1a6c24ed97bc30369e26)
Co-authored-by: Francesco Giannuzzo <[email protected]>
- app.py +0 -0
- evaluation_p_metrics.csv +0 -0
- style.css +28 -8
- utilities.py +66 -11
app.py
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
evaluation_p_metrics.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
style.css
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
|
|
| 1 |
.prose h1 {
|
| 2 |
-
font-family: '
|
| 3 |
font-size: 3rem;
|
| 4 |
-
font-weight:
|
| 5 |
-
text-transform:
|
| 6 |
-
letter-spacing:
|
| 7 |
text-align: center;
|
| 8 |
-
color: #
|
| 9 |
-
background: linear-gradient(45deg, #d4c9cc, #c4b8bb);
|
| 10 |
-
-webkit-background-clip: text;
|
| 11 |
-
-webkit-text-fill-color: transparent;
|
| 12 |
padding: 20px;
|
| 13 |
margin: 20px 0;
|
| 14 |
position: relative;
|
| 15 |
}
|
| 16 |
|
|
|
|
| 17 |
.prose h1::after {
|
| 18 |
content: "";
|
| 19 |
width: 60px;
|
|
@@ -24,6 +23,23 @@
|
|
| 24 |
border-radius: 2px;
|
| 25 |
}
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
#bar_plot, #line_plot {
|
| 28 |
width: 100% !important;
|
| 29 |
max-width: none !important;
|
|
@@ -45,6 +61,7 @@
|
|
| 45 |
margin: 20px 0;
|
| 46 |
position: center;
|
| 47 |
}
|
|
|
|
| 48 |
.fish{
|
| 49 |
font-family: 'Poppins', sans-serif;
|
| 50 |
font-size: 1.5rem;
|
|
@@ -75,11 +92,13 @@
|
|
| 75 |
/*margin: 20px 0;*/
|
| 76 |
position: center;
|
| 77 |
}
|
|
|
|
| 78 |
.barcontainer {
|
| 79 |
display: flex;
|
| 80 |
justify-content: center;
|
| 81 |
align-items: center;
|
| 82 |
}
|
|
|
|
| 83 |
.leftarrow, .rightarrow {
|
| 84 |
display: flex;
|
| 85 |
justify-content: center;
|
|
@@ -87,6 +106,7 @@
|
|
| 87 |
font-size: 2.7rem;
|
| 88 |
color: #1d60dd;
|
| 89 |
}
|
|
|
|
| 90 |
.leftarrow {
|
| 91 |
transform: rotate(-270deg);
|
| 92 |
}
|
|
|
|
| 1 |
+
/* Titoli principali h1 */
|
| 2 |
.prose h1 {
|
| 3 |
+
font-family: 'Playfair Display', serif;
|
| 4 |
font-size: 3rem;
|
| 5 |
+
font-weight: 600;
|
| 6 |
+
text-transform: none;
|
| 7 |
+
letter-spacing: 0.5px;
|
| 8 |
text-align: center;
|
| 9 |
+
color: #ffffff;
|
|
|
|
|
|
|
|
|
|
| 10 |
padding: 20px;
|
| 11 |
margin: 20px 0;
|
| 12 |
position: relative;
|
| 13 |
}
|
| 14 |
|
| 15 |
+
/* Linea decorativa sotto l'h1 */
|
| 16 |
.prose h1::after {
|
| 17 |
content: "";
|
| 18 |
width: 60px;
|
|
|
|
| 23 |
border-radius: 2px;
|
| 24 |
}
|
| 25 |
|
| 26 |
+
/* Titoli secondari h2 */
|
| 27 |
+
.prose h2 {
|
| 28 |
+
font-family: 'Playfair Display', serif;
|
| 29 |
+
font-size: 2.2rem;
|
| 30 |
+
font-weight: 500;
|
| 31 |
+
letter-spacing: 0.3px;
|
| 32 |
+
color: #ffffff;
|
| 33 |
+
text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.4);
|
| 34 |
+
padding: 10px 0;
|
| 35 |
+
margin: 10px 0 20px 0;
|
| 36 |
+
text-align: left;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
body, label, button, span, li, p, .prose {
|
| 40 |
+
font-family: 'Playfair Display', serif;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
#bar_plot, #line_plot {
|
| 44 |
width: 100% !important;
|
| 45 |
max-width: none !important;
|
|
|
|
| 61 |
margin: 20px 0;
|
| 62 |
position: center;
|
| 63 |
}
|
| 64 |
+
|
| 65 |
.fish{
|
| 66 |
font-family: 'Poppins', sans-serif;
|
| 67 |
font-size: 1.5rem;
|
|
|
|
| 92 |
/*margin: 20px 0;*/
|
| 93 |
position: center;
|
| 94 |
}
|
| 95 |
+
|
| 96 |
.barcontainer {
|
| 97 |
display: flex;
|
| 98 |
justify-content: center;
|
| 99 |
align-items: center;
|
| 100 |
}
|
| 101 |
+
|
| 102 |
.leftarrow, .rightarrow {
|
| 103 |
display: flex;
|
| 104 |
justify-content: center;
|
|
|
|
| 106 |
font-size: 2.7rem;
|
| 107 |
color: #1d60dd;
|
| 108 |
}
|
| 109 |
+
|
| 110 |
.leftarrow {
|
| 111 |
transform: rotate(-270deg);
|
| 112 |
}
|
utilities.py
CHANGED
|
@@ -1,32 +1,35 @@
|
|
| 1 |
import csv
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import sqlite3
|
| 4 |
import gradio as gr
|
| 5 |
import os
|
| 6 |
from qatch.connectors.sqlite_connector import SqliteConnector
|
| 7 |
-
|
| 8 |
-
def carica_sqlite(file_path, db_id):
|
| 9 |
conn = sqlite3.connect(file_path)
|
| 10 |
cursor = conn.cursor()
|
| 11 |
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
|
| 12 |
tabelle = cursor.fetchall()
|
| 13 |
tabelle = [tabella for tabella in tabelle if tabella[0] != 'sqlite_sequence']
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
dfs = {}
|
| 16 |
for tabella in tabelle:
|
| 17 |
nome_tabella = tabella[0]
|
| 18 |
df = pd.read_sql_query(f"SELECT * FROM {nome_tabella}", conn)
|
| 19 |
dfs[nome_tabella] = df
|
| 20 |
conn.close()
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
# )
|
| 26 |
return data_output
|
| 27 |
|
| 28 |
# Funzione per leggere un file CSV
|
| 29 |
-
def
|
| 30 |
df = pd.read_csv(file)
|
| 31 |
return df
|
| 32 |
|
|
@@ -44,7 +47,7 @@ def load_data(data_path : str, db_name : str):
|
|
| 44 |
if data_path.endswith(".sqlite") :
|
| 45 |
data_output = carica_sqlite(data_path, db_name)
|
| 46 |
elif data_path.endswith(".csv"):
|
| 47 |
-
data_output['data_frames'] = {f"{table_name}_table" :
|
| 48 |
elif data_path.endswith(".xlsx"):
|
| 49 |
data_output['data_frames'] = carica_excel(data_path)
|
| 50 |
else:
|
|
@@ -74,4 +77,56 @@ def csv_to_dict(file_path):
|
|
| 74 |
if "price" in row:
|
| 75 |
row["price"] = float(row["price"])
|
| 76 |
data.append(row)
|
| 77 |
-
return data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import csv
|
| 2 |
+
import re
|
| 3 |
import pandas as pd
|
| 4 |
import sqlite3
|
| 5 |
import gradio as gr
|
| 6 |
import os
|
| 7 |
from qatch.connectors.sqlite_connector import SqliteConnector
|
| 8 |
+
def extract_tables(file_path):
|
|
|
|
| 9 |
conn = sqlite3.connect(file_path)
|
| 10 |
cursor = conn.cursor()
|
| 11 |
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
|
| 12 |
tabelle = cursor.fetchall()
|
| 13 |
tabelle = [tabella for tabella in tabelle if tabella[0] != 'sqlite_sequence']
|
| 14 |
+
return tabelle
|
| 15 |
+
|
| 16 |
+
def extract_dataframes(file_path):
|
| 17 |
+
conn = sqlite3.connect(file_path)
|
| 18 |
+
tabelle = extract_tables(file_path)
|
| 19 |
dfs = {}
|
| 20 |
for tabella in tabelle:
|
| 21 |
nome_tabella = tabella[0]
|
| 22 |
df = pd.read_sql_query(f"SELECT * FROM {nome_tabella}", conn)
|
| 23 |
dfs[nome_tabella] = df
|
| 24 |
conn.close()
|
| 25 |
+
return dfs
|
| 26 |
+
|
| 27 |
+
def carica_sqlite(file_path, db_id):
|
| 28 |
+
data_output = {'data_frames': extract_dataframes(file_path),'db':SqliteConnector(relative_db_path=file_path, db_name=db_id)}
|
|
|
|
| 29 |
return data_output
|
| 30 |
|
| 31 |
# Funzione per leggere un file CSV
|
| 32 |
+
def load_csv(file):
|
| 33 |
df = pd.read_csv(file)
|
| 34 |
return df
|
| 35 |
|
|
|
|
| 47 |
if data_path.endswith(".sqlite") :
|
| 48 |
data_output = carica_sqlite(data_path, db_name)
|
| 49 |
elif data_path.endswith(".csv"):
|
| 50 |
+
data_output['data_frames'] = {f"{table_name}_table" : load_csv(data_path)}
|
| 51 |
elif data_path.endswith(".xlsx"):
|
| 52 |
data_output['data_frames'] = carica_excel(data_path)
|
| 53 |
else:
|
|
|
|
| 77 |
if "price" in row:
|
| 78 |
row["price"] = float(row["price"])
|
| 79 |
data.append(row)
|
| 80 |
+
return data
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def increment_filename(filename):
|
| 84 |
+
base, ext = os.path.splitext(filename)
|
| 85 |
+
numbers = re.findall(r'\d+', base)
|
| 86 |
+
|
| 87 |
+
if numbers:
|
| 88 |
+
max_num = max(map(int, numbers)) + 1
|
| 89 |
+
new_base = re.sub(r'(\d+)', lambda m: str(max_num) if int(m.group(1)) == max(map(int, numbers)) else m.group(1), base)
|
| 90 |
+
else:
|
| 91 |
+
new_base = base + '1'
|
| 92 |
+
|
| 93 |
+
return new_base + ext
|
| 94 |
+
|
| 95 |
+
def prepare_prompt(prompt, question, schema, samples):
|
| 96 |
+
prompt = prompt.replace("{schema}", schema).replace("{question}", question)
|
| 97 |
+
prompt += f" Some istanze: {samples}"
|
| 98 |
+
return prompt
|
| 99 |
+
|
| 100 |
+
def generate_some_samples(connector, tbl_name):
|
| 101 |
+
samples = []
|
| 102 |
+
query = f"SELECT * FROM {tbl_name} LIMIT 3"
|
| 103 |
+
try:
|
| 104 |
+
sample_data = connector.execute_query(query)
|
| 105 |
+
samples.append(str(sample_data))
|
| 106 |
+
except Exception as e:
|
| 107 |
+
samples.append(f"Error: {e}")
|
| 108 |
+
return samples
|
| 109 |
+
def extract_tables_dict(pnp_path):
|
| 110 |
+
tables_dict = {}
|
| 111 |
+
# df = pd.read_csv(pnp_path)
|
| 112 |
+
# with open(pnp_path, mode='r', encoding='utf-8') as file:
|
| 113 |
+
# reader = csv.DictReader(file)
|
| 114 |
+
# for row in reader:
|
| 115 |
+
# tbl_name = row.get("tbl_name")
|
| 116 |
+
# db_path = row.get("db_path")
|
| 117 |
+
# if tbl_name and db_path:
|
| 118 |
+
# print(db_path, tbl_name)
|
| 119 |
+
# connector = SqliteConnector(relative_db_path=db_path, db_name=os.path.basename(db_path))
|
| 120 |
+
# instances = generate_some_samples(connector, tbl_name)
|
| 121 |
+
# if tbl_name not in tables_dict:
|
| 122 |
+
# tables_dict[tbl_name] = []
|
| 123 |
+
# tables_dict[tbl_name].extend(instances)
|
| 124 |
+
|
| 125 |
+
with open(pnp_path, mode='r', encoding='utf-8') as file:
|
| 126 |
+
reader = csv.DictReader(file)
|
| 127 |
+
for row in reader:
|
| 128 |
+
tbl_name = row.get("tbl_name")
|
| 129 |
+
if tbl_name not in tables_dict:
|
| 130 |
+
tables_dict[tbl_name] = []
|
| 131 |
+
#tables_dict[tbl_name].append(row)
|
| 132 |
+
return tables_dict
|