Spaces:
Building
Building
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,290 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
from mistralai.client import MistralClient
|
@@ -13,7 +300,7 @@ client = MistralClient(api_key=api_key)
|
|
13 |
|
14 |
def generate_goals(input_var):
|
15 |
messages = [
|
16 |
-
ChatMessage(role="user", content=f"Generate
|
17 |
]
|
18 |
|
19 |
try:
|
@@ -23,52 +310,29 @@ def generate_goals(input_var):
|
|
23 |
except Exception as e:
|
24 |
return f"An error occurred: {str(e)}"
|
25 |
|
26 |
-
# HTML content
|
27 |
html_content = """
|
28 |
<!DOCTYPE html>
|
29 |
<html lang="en">
|
30 |
<head>
|
31 |
<meta charset="UTF-8">
|
32 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
33 |
-
<title>
|
34 |
-
<script src="https://
|
35 |
<style>
|
36 |
-
|
37 |
-
#
|
38 |
-
.goal { cursor: pointer; }
|
39 |
-
#info { margin-top: 20px; font-weight: bold; }
|
40 |
-
#selectedGoal { margin-top: 10px; padding: 10px; border: 1px solid #ccc; background-color: #f0f0f0; }
|
41 |
-
#hoverInfo {
|
42 |
-
position: absolute;
|
43 |
-
padding: 10px;
|
44 |
-
background-color: rgba(255, 255, 255, 0.9);
|
45 |
-
border: 1px solid #ccc;
|
46 |
-
border-radius: 5px;
|
47 |
-
font-size: 14px;
|
48 |
-
max-width: 300px;
|
49 |
-
display: none;
|
50 |
-
}
|
51 |
-
#responseBox {
|
52 |
-
margin-top: 20px;
|
53 |
-
padding: 10px;
|
54 |
-
border: 1px solid #ccc;
|
55 |
-
background-color: #e0f7fa;
|
56 |
-
}
|
57 |
</style>
|
58 |
</head>
|
59 |
<body>
|
60 |
-
<h1>
|
61 |
-
<div id="
|
62 |
-
<div id="
|
63 |
-
<div id="selectedGoal"></div>
|
64 |
-
<div id="hoverInfo"></div>
|
65 |
-
<div id="responseBox"></div>
|
66 |
|
67 |
<script>
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
const goals = [
|
72 |
{ id: 1, x: 100, y: 400, name: "Automate Data Import", description: "Develop scripts to automate exam data extraction from various sources (CSV, Excel, databases) using Pandas read_* functions." },
|
73 |
{ id: 2, x: 200, y: 300, name: "Data Cleaning", description: "Implement robust data cleaning processes to handle missing values, outliers, and inconsistencies in exam data using Pandas methods like dropna(), fillna(), and apply()." },
|
74 |
{ id: 3, x: 300, y: 200, name: "Data Transformation", description: "Utilize Pandas for complex data transformations such as pivoting exam results, melting question-wise scores, and creating derived features for analysis." },
|
@@ -144,128 +408,86 @@ html_content = """
|
|
144 |
{ source: 26, target: 29 }
|
145 |
];
|
146 |
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
.
|
173 |
-
.
|
174 |
-
.
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
.
|
190 |
-
.attr("font-size", "12px");
|
191 |
-
|
192 |
-
// Hover info box
|
193 |
-
const hoverInfo = d3.select("#hoverInfo");
|
194 |
-
|
195 |
-
// Add hover effects on goal nodes
|
196 |
-
goalNodes.on("mouseover", function(event, d) {
|
197 |
-
d3.select(this).attr("r", 15);
|
198 |
-
hoverInfo.style("display", "block")
|
199 |
-
.style("left", (event.pageX + 10) + "px")
|
200 |
-
.style("top", (event.pageY - 10) + "px")
|
201 |
-
.html(`<strong>${d.name}</strong><br>${d.description}`);
|
202 |
-
}).on("mouseout", function() {
|
203 |
-
d3.select(this).attr("r", 10);
|
204 |
-
hoverInfo.style("display", "none");
|
205 |
-
});
|
206 |
-
|
207 |
-
// Handle click event on goal nodes
|
208 |
-
goalNodes.on("click", async function(event, d) {
|
209 |
-
updateSelectedGoalInfo(d);
|
210 |
-
|
211 |
-
try {
|
212 |
-
const response = await fetch('generate_goals', {
|
213 |
-
method: 'POST',
|
214 |
-
headers: {
|
215 |
-
'Content-Type': 'application/json',
|
216 |
-
},
|
217 |
-
body: JSON.stringify({ input_var: d.name })
|
218 |
-
});
|
219 |
-
|
220 |
-
if (!response.ok) {
|
221 |
-
throw new Error(`HTTP error! status: ${response.status}`);
|
222 |
-
}
|
223 |
-
|
224 |
-
const data = await response.json();
|
225 |
-
displayResponse(data.content);
|
226 |
-
} catch (error) {
|
227 |
-
console.error("There was an error fetching the response:", error);
|
228 |
-
displayResponse("An error occurred while generating the response.");
|
229 |
-
}
|
230 |
-
});
|
231 |
-
|
232 |
-
// Function to update selected goal information
|
233 |
-
function updateSelectedGoalInfo(goal) {
|
234 |
-
const selectedGoalDiv = d3.select("#selectedGoal");
|
235 |
-
selectedGoalDiv.html(`
|
236 |
-
<h3>${goal.name}</h3>
|
237 |
-
<p>${goal.description}</p>
|
238 |
-
`);
|
239 |
-
}
|
240 |
-
|
241 |
-
// Function to display the response from the server
|
242 |
-
function displayResponse(content) {
|
243 |
-
const responseBox = d3.select("#responseBox");
|
244 |
-
responseBox.html(`
|
245 |
-
<h2>Response</h2>
|
246 |
-
<p>${content}</p>
|
247 |
-
`);
|
248 |
-
}
|
249 |
-
|
250 |
-
// Handle mouse move event to highlight the closest goal
|
251 |
-
svg.on("mousemove", function(event) {
|
252 |
-
const [x, y] = d3.pointer(event);
|
253 |
-
const closest = findClosestGoal(x, y);
|
254 |
-
highlightClosestGoal(closest);
|
255 |
});
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
</script>
|
270 |
</body>
|
271 |
</html>
|
@@ -274,12 +496,11 @@ html_content = """
|
|
274 |
# Gradio interface
|
275 |
iface = gr.Interface(
|
276 |
fn=generate_goals,
|
277 |
-
inputs=gr.Textbox(
|
278 |
-
outputs=gr.Textbox(
|
279 |
title="Exam Data Analysis Goals Generator",
|
280 |
description="Click on a goal in the visualization to generate related goals.",
|
281 |
allow_flagging="never",
|
282 |
-
theme="default",
|
283 |
css=html_content
|
284 |
)
|
285 |
|
|
|
1 |
+
# import gradio as gr
|
2 |
+
# import os
|
3 |
+
# from mistralai.client import MistralClient
|
4 |
+
# from mistralai.models.chat_completion import ChatMessage
|
5 |
+
|
6 |
+
# # Ensure the environment variable for the API key is set
|
7 |
+
# api_key = os.getenv("MISTRAL_API_KEY")
|
8 |
+
# if not api_key:
|
9 |
+
# raise ValueError("MISTRAL_API_KEY environment variable not set")
|
10 |
+
|
11 |
+
# model = "mistral-tiny"
|
12 |
+
# client = MistralClient(api_key=api_key)
|
13 |
+
|
14 |
+
# def generate_goals(input_var):
|
15 |
+
# messages = [
|
16 |
+
# ChatMessage(role="user", content=f"Generate 10 specific, industry relevant goals for {input_var} using Python and Pandas. Each goal should include a brief name and a one-sentence description of the task or skill. Focus on practical applications in educational assessment, covering areas such as data processing, statistical analysis, visualization, and advanced techniques")
|
17 |
+
# ]
|
18 |
+
|
19 |
+
# try:
|
20 |
+
# response = client.chat(model=model, messages=messages)
|
21 |
+
# content = response.choices[0].message.content
|
22 |
+
# return content
|
23 |
+
# except Exception as e:
|
24 |
+
# return f"An error occurred: {str(e)}"
|
25 |
+
|
26 |
+
# # HTML content
|
27 |
+
# html_content = """
|
28 |
+
# <!DOCTYPE html>
|
29 |
+
# <html lang="en">
|
30 |
+
# <head>
|
31 |
+
# <meta charset="UTF-8">
|
32 |
+
# <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
33 |
+
# <title>Comprehensive Exam Data Analysis with Pandas - 30 Industry Goals with Connections</title>
|
34 |
+
# <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/7.8.5/d3.min.js"></script>
|
35 |
+
# <style>
|
36 |
+
# body { font-family: Arial, sans-serif; margin: 20px; }
|
37 |
+
# #goalSpace { border: 1px solid #ccc; margin-bottom: 20px; }
|
38 |
+
# .goal { cursor: pointer; }
|
39 |
+
# #info { margin-top: 20px; font-weight: bold; }
|
40 |
+
# #selectedGoal { margin-top: 10px; padding: 10px; border: 1px solid #ccc; background-color: #f0f0f0; }
|
41 |
+
# #hoverInfo {
|
42 |
+
# position: absolute;
|
43 |
+
# padding: 10px;
|
44 |
+
# background-color: rgba(255, 255, 255, 0.9);
|
45 |
+
# border: 1px solid #ccc;
|
46 |
+
# border-radius: 5px;
|
47 |
+
# font-size: 14px;
|
48 |
+
# max-width: 300px;
|
49 |
+
# display: none;
|
50 |
+
# }
|
51 |
+
# #responseBox {
|
52 |
+
# margin-top: 20px;
|
53 |
+
# padding: 10px;
|
54 |
+
# border: 1px solid #ccc;
|
55 |
+
# background-color: #e0f7fa;
|
56 |
+
# }
|
57 |
+
# </style>
|
58 |
+
# </head>
|
59 |
+
# <body>
|
60 |
+
# <h1>Comprehensive Exam Data Analysis with Pandas - 30 Industry Goals with Connections</h1>
|
61 |
+
# <div id="goalSpace"></div>
|
62 |
+
# <div id="info"></div>
|
63 |
+
# <div id="selectedGoal"></div>
|
64 |
+
# <div id="hoverInfo"></div>
|
65 |
+
# <div id="responseBox"></div>
|
66 |
+
|
67 |
+
# <script>
|
68 |
+
# const width = 1200;
|
69 |
+
# const height = 800;
|
70 |
+
# // Define the goals and connections data
|
71 |
+
# const goals = [
|
72 |
+
# { id: 1, x: 100, y: 400, name: "Automate Data Import", description: "Develop scripts to automate exam data extraction from various sources (CSV, Excel, databases) using Pandas read_* functions." },
|
73 |
+
# { id: 2, x: 200, y: 300, name: "Data Cleaning", description: "Implement robust data cleaning processes to handle missing values, outliers, and inconsistencies in exam data using Pandas methods like dropna(), fillna(), and apply()." },
|
74 |
+
# { id: 3, x: 300, y: 200, name: "Data Transformation", description: "Utilize Pandas for complex data transformations such as pivoting exam results, melting question-wise scores, and creating derived features for analysis." },
|
75 |
+
# { id: 4, x: 400, y: 300, name: "Statistical Analysis", description: "Develop functions to automate statistical analysis of exam results, including descriptive statistics, hypothesis testing, and correlation analysis using Pandas and SciPy." },
|
76 |
+
# { id: 5, x: 500, y: 400, name: "Performance Metrics", description: "Create custom functions to calculate industry-standard exam performance metrics like item difficulty, discrimination index, and reliability coefficients using Pandas operations." },
|
77 |
+
# { id: 6, x: 200, y: 500, name: "Data Filtering", description: "Implement advanced filtering techniques to segment exam data based on various criteria (e.g., demographic info, score ranges) using boolean indexing and query() method in Pandas." },
|
78 |
+
# { id: 7, x: 300, y: 600, name: "Reporting Automation", description: "Develop automated reporting systems that use Pandas groupby() and agg() functions to generate summary statistics and performance reports for different exam cohorts." },
|
79 |
+
# { id: 8, x: 400, y: 500, name: "Data Visualization", description: "Create interactive dashboards for exam data visualization using Pandas with Plotly or Bokeh, allowing stakeholders to explore results dynamically." },
|
80 |
+
# { id: 9, x: 500, y: 600, name: "Time Series Analysis", description: "Implement time series analysis techniques using Pandas datetime functionality to track and forecast exam performance trends over multiple test administrations." },
|
81 |
+
# { id: 10, x: 300, y: 400, name: "Data Integration", description: "Develop processes to merge exam data with other relevant datasets (e.g., student information systems, learning management systems) using Pandas merge() and join() operations." },
|
82 |
+
# { id: 11, x: 600, y: 300, name: "Performance Optimization", description: "Improve the efficiency of Pandas operations on large exam datasets by utilizing techniques like chunking, multiprocessing, and query optimization." },
|
83 |
+
# { id: 12, x: 700, y: 400, name: "Machine Learning Integration", description: "Integrate machine learning models with Pandas for predictive analytics, such as predicting exam success or identifying at-risk students based on historical data." },
|
84 |
+
# { id: 13, x: 800, y: 500, name: "Custom Indexing", description: "Implement custom indexing strategies in Pandas to efficiently handle hierarchical exam data structures and improve data access patterns." },
|
85 |
+
# { id: 14, x: 900, y: 400, name: "Data Anonymization", description: "Develop Pandas-based workflows to anonymize sensitive exam data, ensuring compliance with privacy regulations while maintaining data utility for analysis." },
|
86 |
+
# { id: 15, x: 1000, y: 300, name: "Exam Item Analysis", description: "Create specialized functions using Pandas to perform detailed item analysis, including distractor analysis and reliability calculations for individual exam questions." },
|
87 |
+
# { id: 16, x: 600, y: 500, name: "Longitudinal Analysis", description: "Implement Pandas-based methods for tracking student performance across multiple exams over time, identifying learning trends and progress patterns." },
|
88 |
+
# { id: 17, x: 700, y: 600, name: "Adaptive Testing Analysis", description: "Develop analysis pipelines using Pandas to evaluate and optimize adaptive testing algorithms, including item selection strategies and scoring methods." },
|
89 |
+
# { id: 18, x: 800, y: 700, name: "Exam Equating", description: "Create Pandas workflows to perform exam equating, ensuring comparability of scores across different versions or administrations of an exam." },
|
90 |
+
# { id: 19, x: 900, y: 600, name: "Response Time Analysis", description: "Utilize Pandas to analyze exam response times, identifying patterns that may indicate guessing, test-taking strategies, or item difficulty." },
|
91 |
+
# { id: 20, x: 1000, y: 500, name: "Collaborative Filtering", description: "Implement collaborative filtering techniques using Pandas to recommend study materials or practice questions based on exam performance patterns." },
|
92 |
+
# { id: 21, x: 400, y: 700, name: "Exam Fraud Detection", description: "Develop anomaly detection algorithms using Pandas to identify potential exam fraud or unusual response patterns in large-scale testing programs." },
|
93 |
+
# { id: 22, x: 500, y: 800, name: "Standard Setting", description: "Create Pandas-based tools to assist in standard setting processes, analyzing expert judgments and examinee data to establish performance standards." },
|
94 |
+
# { id: 23, x: 600, y: 700, name: "Automated Reporting", description: "Implement automated report generation using Pandas and libraries like Jinja2 to create customized, data-driven exam reports for various stakeholders." },
|
95 |
+
# { id: 24, x: 700, y: 800, name: "Cross-validation", description: "Develop cross-validation frameworks using Pandas to assess the reliability and generalizability of predictive models in educational assessment contexts." },
|
96 |
+
# { id: 25, x: 800, y: 300, name: "API Integration", description: "Create Pandas-based interfaces to integrate exam data analysis workflows with external APIs, facilitating real-time data exchange and reporting." },
|
97 |
+
# { id: 26, x: 900, y: 200, name: "Natural Language Processing", description: "Implement NLP techniques using Pandas and libraries like NLTK to analyze free-text responses in exams, enabling automated scoring and content analysis." },
|
98 |
+
# { id: 27, x: 1000, y: 100, name: "Exam Blueprint Analysis", description: "Develop Pandas workflows to analyze exam blueprints, ensuring content coverage and alignment with learning objectives across multiple test forms." },
|
99 |
+
# { id: 28, x: 100, y: 600, name: "Differential Item Functioning", description: "Implement statistical methods using Pandas to detect and analyze differential item functioning (DIF) in exams, ensuring fairness across different demographic groups." },
|
100 |
+
# { id: 29, x: 200, y: 700, name: "Automated Feedback Generation", description: "Create Pandas-based systems to generate personalized feedback for test-takers based on their exam performance and identified areas for improvement." },
|
101 |
+
# { id: 30, x: 300, y: 800, name: "Exam Security Analysis", description: "Develop analytical tools using Pandas to assess and enhance exam security, including analysis of item exposure rates and detection of potential security breaches." }
|
102 |
+
# ];
|
103 |
+
# const connections = [
|
104 |
+
# { source: 1, target: 2 },
|
105 |
+
# { source: 2, target: 3 },
|
106 |
+
# { source: 3, target: 4 },
|
107 |
+
# { source: 4, target: 5 },
|
108 |
+
# { source: 5, target: 7 },
|
109 |
+
# { source: 6, target: 7 },
|
110 |
+
# { source: 7, target: 8 },
|
111 |
+
# { source: 8, target: 9 },
|
112 |
+
# { source: 9, target: 16 },
|
113 |
+
# { source: 10, target: 13 },
|
114 |
+
# { source: 11, target: 12 },
|
115 |
+
# { source: 12, target: 20 },
|
116 |
+
# { source: 13, target: 16 },
|
117 |
+
# { source: 14, target: 21 },
|
118 |
+
# { source: 15, target: 17 },
|
119 |
+
# { source: 16, target: 18 },
|
120 |
+
# { source: 17, target: 19 },
|
121 |
+
# { source: 18, target: 22 },
|
122 |
+
# { source: 19, target: 21 },
|
123 |
+
# { source: 20, target: 29 },
|
124 |
+
# { source: 21, target: 30 },
|
125 |
+
# { source: 22, target: 23 },
|
126 |
+
# { source: 23, target: 25 },
|
127 |
+
# { source: 24, target: 12 },
|
128 |
+
# { source: 25, target: 23 },
|
129 |
+
# { source: 26, target: 15 },
|
130 |
+
# { source: 27, target: 15 },
|
131 |
+
# { source: 28, target: 22 },
|
132 |
+
# { source: 29, target: 23 },
|
133 |
+
# { source: 30, target: 21 },
|
134 |
+
# // Additional connections for more interconnectivity
|
135 |
+
# { source: 1, target: 10 },
|
136 |
+
# { source: 2, target: 6 },
|
137 |
+
# { source: 3, target: 13 },
|
138 |
+
# { source: 4, target: 15 },
|
139 |
+
# { source: 5, target: 28 },
|
140 |
+
# { source: 8, target: 23 },
|
141 |
+
# { source: 11, target: 25 },
|
142 |
+
# { source: 14, target: 30 },
|
143 |
+
# { source: 24, target: 17 },
|
144 |
+
# { source: 26, target: 29 }
|
145 |
+
# ];
|
146 |
+
|
147 |
+
|
148 |
+
# // Create the SVG container for the goals and connections
|
149 |
+
# const svg = d3.select("#goalSpace")
|
150 |
+
# .append("svg")
|
151 |
+
# .attr("width", width)
|
152 |
+
# .attr("height", height);
|
153 |
+
|
154 |
+
# // Draw connections between goals
|
155 |
+
# const links = svg.selectAll("line")
|
156 |
+
# .data(connections)
|
157 |
+
# .enter()
|
158 |
+
# .append("line")
|
159 |
+
# .attr("x1", d => goals.find(g => g.id === d.source).x)
|
160 |
+
# .attr("y1", d => goals.find(g => g.id === d.source).y)
|
161 |
+
# .attr("x2", d => goals.find(g => g.id === d.target).x)
|
162 |
+
# .attr("y2", d => goals.find(g => g.id === d.target).y)
|
163 |
+
# .attr("stroke", "#999")
|
164 |
+
# .attr("stroke-width", 1)
|
165 |
+
# .attr("stroke-opacity", 0.6);
|
166 |
+
|
167 |
+
# // Draw goal nodes
|
168 |
+
# const goalNodes = svg.selectAll("circle")
|
169 |
+
# .data(goals)
|
170 |
+
# .enter()
|
171 |
+
# .append("circle")
|
172 |
+
# .attr("cx", d => d.x)
|
173 |
+
# .attr("cy", d => d.y)
|
174 |
+
# .attr("r", 10)
|
175 |
+
# .attr("fill", d => {
|
176 |
+
# if (d.id <= 10) return "blue";
|
177 |
+
# if (d.id <= 20) return "green";
|
178 |
+
# return "orange";
|
179 |
+
# })
|
180 |
+
# .attr("class", "goal");
|
181 |
+
|
182 |
+
# // Add labels to the goals
|
183 |
+
# const goalLabels = svg.selectAll("text")
|
184 |
+
# .data(goals)
|
185 |
+
# .enter()
|
186 |
+
# .append("text")
|
187 |
+
# .attr("x", d => d.x + 15)
|
188 |
+
# .attr("y", d => d.y)
|
189 |
+
# .text(d => d.name)
|
190 |
+
# .attr("font-size", "12px");
|
191 |
+
|
192 |
+
# // Hover info box
|
193 |
+
# const hoverInfo = d3.select("#hoverInfo");
|
194 |
+
|
195 |
+
# // Add hover effects on goal nodes
|
196 |
+
# goalNodes.on("mouseover", function(event, d) {
|
197 |
+
# d3.select(this).attr("r", 15);
|
198 |
+
# hoverInfo.style("display", "block")
|
199 |
+
# .style("left", (event.pageX + 10) + "px")
|
200 |
+
# .style("top", (event.pageY - 10) + "px")
|
201 |
+
# .html(`<strong>${d.name}</strong><br>${d.description}`);
|
202 |
+
# }).on("mouseout", function() {
|
203 |
+
# d3.select(this).attr("r", 10);
|
204 |
+
# hoverInfo.style("display", "none");
|
205 |
+
# });
|
206 |
+
|
207 |
+
# // Handle click event on goal nodes
|
208 |
+
# goalNodes.on("click", async function(event, d) {
|
209 |
+
# updateSelectedGoalInfo(d);
|
210 |
+
|
211 |
+
# try {
|
212 |
+
# const response = await fetch('generate_goals', {
|
213 |
+
# method: 'POST',
|
214 |
+
# headers: {
|
215 |
+
# 'Content-Type': 'application/json',
|
216 |
+
# },
|
217 |
+
# body: JSON.stringify({ input_var: d.name })
|
218 |
+
# });
|
219 |
+
|
220 |
+
# if (!response.ok) {
|
221 |
+
# throw new Error(`HTTP error! status: ${response.status}`);
|
222 |
+
# }
|
223 |
+
|
224 |
+
# const data = await response.json();
|
225 |
+
# displayResponse(data.content);
|
226 |
+
# } catch (error) {
|
227 |
+
# console.error("There was an error fetching the response:", error);
|
228 |
+
# displayResponse("An error occurred while generating the response.");
|
229 |
+
# }
|
230 |
+
# });
|
231 |
+
|
232 |
+
# // Function to update selected goal information
|
233 |
+
# function updateSelectedGoalInfo(goal) {
|
234 |
+
# const selectedGoalDiv = d3.select("#selectedGoal");
|
235 |
+
# selectedGoalDiv.html(`
|
236 |
+
# <h3>${goal.name}</h3>
|
237 |
+
# <p>${goal.description}</p>
|
238 |
+
# `);
|
239 |
+
# }
|
240 |
+
|
241 |
+
# // Function to display the response from the server
|
242 |
+
# function displayResponse(content) {
|
243 |
+
# const responseBox = d3.select("#responseBox");
|
244 |
+
# responseBox.html(`
|
245 |
+
# <h2>Response</h2>
|
246 |
+
# <p>${content}</p>
|
247 |
+
# `);
|
248 |
+
# }
|
249 |
+
|
250 |
+
# // Handle mouse move event to highlight the closest goal
|
251 |
+
# svg.on("mousemove", function(event) {
|
252 |
+
# const [x, y] = d3.pointer(event);
|
253 |
+
# const closest = findClosestGoal(x, y);
|
254 |
+
# highlightClosestGoal(closest);
|
255 |
+
# });
|
256 |
+
|
257 |
+
# // Function to find the closest goal to the mouse pointer
|
258 |
+
# function findClosestGoal(x, y) {
|
259 |
+
# return goals.reduce((closest, goal) => {
|
260 |
+
# const distance = Math.sqrt(Math.pow(goal.x - x, 2) + Math.pow(goal.y - y, 2));
|
261 |
+
# return distance < closest.distance ? { goal, distance } : closest;
|
262 |
+
# }, { goal: null, distance: Infinity }).goal;
|
263 |
+
# }
|
264 |
+
|
265 |
+
# // Function to highlight the closest goal
|
266 |
+
# function highlightClosestGoal(goal) {
|
267 |
+
# d3.select("#info").html(`Closest goal: ${goal.name}`);
|
268 |
+
# }
|
269 |
+
# </script>
|
270 |
+
# </body>
|
271 |
+
# </html>
|
272 |
+
# """
|
273 |
+
|
274 |
+
# # Gradio interface
|
275 |
+
# iface = gr.Interface(
|
276 |
+
# fn=generate_goals,
|
277 |
+
# inputs=gr.Textbox(label="Goal Name"),
|
278 |
+
# outputs=gr.Textbox(label="Generated Goals"),
|
279 |
+
# title="Exam Data Analysis Goals Generator",
|
280 |
+
# description="Click on a goal in the visualization to generate related goals.",
|
281 |
+
# allow_flagging="never",
|
282 |
+
# theme="default",
|
283 |
+
# css=html_content
|
284 |
+
# )
|
285 |
+
|
286 |
+
# if __name__ == "__main__":
|
287 |
+
# iface.launch()
|
288 |
import gradio as gr
|
289 |
import os
|
290 |
from mistralai.client import MistralClient
|
|
|
300 |
|
301 |
def generate_goals(input_var):
|
302 |
messages = [
|
303 |
+
ChatMessage(role="user", content=f"Generate 5 specific, industry relevant goals for {input_var} using Python and Pandas in exam data analysis. Each goal should include a brief name and a one-sentence description of the task or skill.")
|
304 |
]
|
305 |
|
306 |
try:
|
|
|
310 |
except Exception as e:
|
311 |
return f"An error occurred: {str(e)}"
|
312 |
|
313 |
+
# HTML content with interactive visualization
|
314 |
html_content = """
|
315 |
<!DOCTYPE html>
|
316 |
<html lang="en">
|
317 |
<head>
|
318 |
<meta charset="UTF-8">
|
319 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
320 |
+
<title>Exam Data Analysis Goals Generator</title>
|
321 |
+
<script src="https://d3js.org/d3.v7.min.js"></script>
|
322 |
<style>
|
323 |
+
#visualization { width: 100%; height: 600px; border: 1px solid #ccc; }
|
324 |
+
#generatedGoals { margin-top: 20px; padding: 10px; border: 1px solid #ccc; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
325 |
</style>
|
326 |
</head>
|
327 |
<body>
|
328 |
+
<h1>Exam Data Analysis Goals Generator</h1>
|
329 |
+
<div id="visualization"></div>
|
330 |
+
<div id="generatedGoals"></div>
|
|
|
|
|
|
|
331 |
|
332 |
<script>
|
333 |
+
const width = 1200;
|
334 |
+
const height = 800;
|
335 |
+
const goals = [
|
|
|
336 |
{ id: 1, x: 100, y: 400, name: "Automate Data Import", description: "Develop scripts to automate exam data extraction from various sources (CSV, Excel, databases) using Pandas read_* functions." },
|
337 |
{ id: 2, x: 200, y: 300, name: "Data Cleaning", description: "Implement robust data cleaning processes to handle missing values, outliers, and inconsistencies in exam data using Pandas methods like dropna(), fillna(), and apply()." },
|
338 |
{ id: 3, x: 300, y: 200, name: "Data Transformation", description: "Utilize Pandas for complex data transformations such as pivoting exam results, melting question-wise scores, and creating derived features for analysis." },
|
|
|
408 |
{ source: 26, target: 29 }
|
409 |
];
|
410 |
|
411 |
+
|
412 |
+
const svg = d3.select("#visualization")
|
413 |
+
.append("svg")
|
414 |
+
.attr("width", width)
|
415 |
+
.attr("height", height);
|
416 |
+
|
417 |
+
const simulation = d3.forceSimulation(goals)
|
418 |
+
.force("link", d3.forceLink(connections).id(d => d.id))
|
419 |
+
.force("charge", d3.forceManyBody().strength(-400))
|
420 |
+
.force("center", d3.forceCenter(width / 2, height / 2));
|
421 |
+
|
422 |
+
const link = svg.append("g")
|
423 |
+
.selectAll("line")
|
424 |
+
.data(connections)
|
425 |
+
.enter().append("line")
|
426 |
+
.attr("stroke", "#999")
|
427 |
+
.attr("stroke-opacity", 0.6);
|
428 |
+
|
429 |
+
const node = svg.append("g")
|
430 |
+
.selectAll("circle")
|
431 |
+
.data(goals)
|
432 |
+
.enter().append("circle")
|
433 |
+
.attr("r", 10)
|
434 |
+
.attr("fill", d => d.color)
|
435 |
+
.call(d3.drag()
|
436 |
+
.on("start", dragstarted)
|
437 |
+
.on("drag", dragged)
|
438 |
+
.on("end", dragended));
|
439 |
+
|
440 |
+
const text = svg.append("g")
|
441 |
+
.selectAll("text")
|
442 |
+
.data(goals)
|
443 |
+
.enter().append("text")
|
444 |
+
.text(d => d.name)
|
445 |
+
.attr("font-size", "12px")
|
446 |
+
.attr("dx", 12)
|
447 |
+
.attr("dy", 4);
|
448 |
+
|
449 |
+
node.on("click", async function(event, d) {
|
450 |
+
const response = await fetch('generate_goals', {
|
451 |
+
method: 'POST',
|
452 |
+
headers: { 'Content-Type': 'application/json' },
|
453 |
+
body: JSON.stringify({ input_var: d.name })
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
454 |
});
|
455 |
+
const data = await response.json();
|
456 |
+
document.getElementById("generatedGoals").innerHTML = `<h2>Generated Goals for ${d.name}</h2><pre>${data}</pre>`;
|
457 |
+
});
|
458 |
+
|
459 |
+
simulation.on("tick", () => {
|
460 |
+
link
|
461 |
+
.attr("x1", d => d.source.x)
|
462 |
+
.attr("y1", d => d.source.y)
|
463 |
+
.attr("x2", d => d.target.x)
|
464 |
+
.attr("y2", d => d.target.y);
|
465 |
+
|
466 |
+
node
|
467 |
+
.attr("cx", d => d.x)
|
468 |
+
.attr("cy", d => d.y);
|
469 |
+
|
470 |
+
text
|
471 |
+
.attr("x", d => d.x)
|
472 |
+
.attr("y", d => d.y);
|
473 |
+
});
|
474 |
+
|
475 |
+
function dragstarted(event) {
|
476 |
+
if (!event.active) simulation.alphaTarget(0.3).restart();
|
477 |
+
event.subject.fx = event.subject.x;
|
478 |
+
event.subject.fy = event.subject.y;
|
479 |
+
}
|
480 |
+
|
481 |
+
function dragged(event) {
|
482 |
+
event.subject.fx = event.x;
|
483 |
+
event.subject.fy = event.y;
|
484 |
+
}
|
485 |
+
|
486 |
+
function dragended(event) {
|
487 |
+
if (!event.active) simulation.alphaTarget(0);
|
488 |
+
event.subject.fx = null;
|
489 |
+
event.subject.fy = null;
|
490 |
+
}
|
491 |
</script>
|
492 |
</body>
|
493 |
</html>
|
|
|
496 |
# Gradio interface
|
497 |
iface = gr.Interface(
|
498 |
fn=generate_goals,
|
499 |
+
inputs=gr.Textbox(visible=False),
|
500 |
+
outputs=gr.Textbox(visible=False),
|
501 |
title="Exam Data Analysis Goals Generator",
|
502 |
description="Click on a goal in the visualization to generate related goals.",
|
503 |
allow_flagging="never",
|
|
|
504 |
css=html_content
|
505 |
)
|
506 |
|