Spaces:
Running
Running
Update index.html
Browse files- index.html +138 -19
index.html
CHANGED
@@ -1,19 +1,138 @@
|
|
1 |
-
<!
|
2 |
-
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Jupyter Agent Interface</title>
|
7 |
+
<style>
|
8 |
+
body {
|
9 |
+
font-family: Arial, sans-serif;
|
10 |
+
margin: 20px;
|
11 |
+
padding: 0;
|
12 |
+
background-color: #f9f9f9;
|
13 |
+
}
|
14 |
+
h1 {
|
15 |
+
color: #333;
|
16 |
+
}
|
17 |
+
.container {
|
18 |
+
max-width: 800px;
|
19 |
+
margin: 0 auto;
|
20 |
+
background: #fff;
|
21 |
+
padding: 20px;
|
22 |
+
border-radius: 8px;
|
23 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
24 |
+
}
|
25 |
+
.file-input {
|
26 |
+
margin-bottom: 20px;
|
27 |
+
}
|
28 |
+
.file-input input {
|
29 |
+
margin-right: 10px;
|
30 |
+
}
|
31 |
+
.results {
|
32 |
+
margin-top: 20px;
|
33 |
+
}
|
34 |
+
.results img {
|
35 |
+
max-width: 100%;
|
36 |
+
height: auto;
|
37 |
+
border: 1px solid #ddd;
|
38 |
+
border-radius: 4px;
|
39 |
+
}
|
40 |
+
.error {
|
41 |
+
color: red;
|
42 |
+
font-weight: bold;
|
43 |
+
}
|
44 |
+
</style>
|
45 |
+
</head>
|
46 |
+
<body>
|
47 |
+
<div class="container">
|
48 |
+
<h1>Jupyter Agent Interface</h1>
|
49 |
+
<div class="file-input">
|
50 |
+
<label for="file-upload">Upload ZIP File:</label>
|
51 |
+
<input type="file" id="file-upload" accept=".zip" />
|
52 |
+
</div>
|
53 |
+
<button id="submit-btn">Submit</button>
|
54 |
+
<div class="results" id="results"></div>
|
55 |
+
</div>
|
56 |
+
|
57 |
+
<script type="module">
|
58 |
+
// Importar el cliente de Gradio
|
59 |
+
import { Client } from "https://cdn.jsdelivr.net/npm/@gradio/client/+esm";
|
60 |
+
|
61 |
+
// Elementos del DOM
|
62 |
+
const fileInput = document.getElementById("file-upload");
|
63 |
+
const submitBtn = document.getElementById("submit-btn");
|
64 |
+
const resultsDiv = document.getElementById("results");
|
65 |
+
|
66 |
+
// Configurar el cliente para el agente Jupyter
|
67 |
+
const client = await Client.connect("data-agents/jupyter-agent");
|
68 |
+
|
69 |
+
// Definir los par谩metros para la solicitud
|
70 |
+
const systemPrompt = `# Data Science Agent Protocol
|
71 |
+
You are an intelligent data science assistant with access to an IPython interpreter. Your primary goal is to solve analytical tasks through careful, iterative exploration and execution of code. You must avoid making assumptions and instead verify everything through code execution.
|
72 |
+
## Core Principles
|
73 |
+
1. Always execute code to verify assumptions
|
74 |
+
2. Break down complex problems into smaller steps
|
75 |
+
3. Learn from execution results
|
76 |
+
4. Maintain clear communication about your process
|
77 |
+
... (el resto del prompt aqu铆) ...
|
78 |
+
Remember: Verification through execution is always better than assumption!`;
|
79 |
+
|
80 |
+
const userInput = `
|
81 |
+
Extract the CSV file (file1) from the ZIP archive (observations), clean and filter the data to keep only the "species_guess", "latitude", and "longitude" columns, then create a new CSV with the filtered information, and finally generate and show a pie chart that displays the percentage distribution of the only main species (those with a frequency over 1%). Only show graphics until over 1%.
|
82 |
+
`;
|
83 |
+
|
84 |
+
const maxNewTokens = 512;
|
85 |
+
const model = "meta-llama/Llama-3.1-70B-Instruct";
|
86 |
+
|
87 |
+
// Manejar el env铆o del formulario
|
88 |
+
submitBtn.addEventListener("click", async () => {
|
89 |
+
if (!fileInput.files.length) {
|
90 |
+
resultsDiv.innerHTML = `<p class="error">Please upload a ZIP file.</p>`;
|
91 |
+
return;
|
92 |
+
}
|
93 |
+
|
94 |
+
// Limpiar resultados anteriores
|
95 |
+
resultsDiv.innerHTML = "<p>Processing...</p>";
|
96 |
+
|
97 |
+
try {
|
98 |
+
// Leer el archivo seleccionado
|
99 |
+
const file = fileInput.files[0];
|
100 |
+
const result = await client.predict("/execute_jupyter_agent", {
|
101 |
+
sytem_prompt: systemPrompt,
|
102 |
+
user_input: userInput,
|
103 |
+
max_new_tokens: maxNewTokens,
|
104 |
+
model: model,
|
105 |
+
files: [file], // Enviar el archivo como parte de la solicitud
|
106 |
+
});
|
107 |
+
|
108 |
+
// Mostrar los resultados
|
109 |
+
const htmlContent = result.data[0]; // Resultado en formato HTML
|
110 |
+
resultsDiv.innerHTML = htmlContent;
|
111 |
+
|
112 |
+
// Extraer y mostrar la 煤ltima imagen del HTML
|
113 |
+
extractAndDisplayLastImage(htmlContent);
|
114 |
+
} catch (error) {
|
115 |
+
resultsDiv.innerHTML = `<p class="error">Error: ${error.message}</p>`;
|
116 |
+
}
|
117 |
+
});
|
118 |
+
|
119 |
+
// Funci贸n para extraer y mostrar la 煤ltima imagen del HTML
|
120 |
+
function extractAndDisplayLastImage(htmlContent) {
|
121 |
+
const imgPattern = /<img[^>]+src="([^">]+)"/g;
|
122 |
+
const matches = [...htmlContent.matchAll(imgPattern)].map(match => match[1]);
|
123 |
+
|
124 |
+
if (!matches.length) {
|
125 |
+
resultsDiv.innerHTML += "<p>No images found in the response.</p>";
|
126 |
+
return;
|
127 |
+
}
|
128 |
+
|
129 |
+
const lastImgSrc = matches[matches.length - 1];
|
130 |
+
const imgElement = document.createElement("img");
|
131 |
+
imgElement.src = lastImgSrc;
|
132 |
+
imgElement.style.maxWidth = "100%";
|
133 |
+
imgElement.style.height = "auto";
|
134 |
+
resultsDiv.appendChild(imgElement);
|
135 |
+
}
|
136 |
+
</script>
|
137 |
+
</body>
|
138 |
+
</html>
|