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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 493 |
from http.server import HTTPServer, SimpleHTTPRequestHandler
|
| 494 |
-
from pyngrok import ngrok
|
| 495 |
import os
|
| 496 |
from mistralai.client import MistralClient
|
| 497 |
from mistralai.models.chat_completion import ChatMessage
|
|
@@ -646,8 +808,7 @@ class MyHandler(SimpleHTTPRequestHandler):
|
|
| 646 |
self.send_error(404)
|
| 647 |
|
| 648 |
if __name__ == '__main__':
|
| 649 |
-
port = 7860
|
| 650 |
-
server = HTTPServer(('', port), MyHandler)
|
| 651 |
-
|
| 652 |
-
print(f" * ngrok tunnel \"{public_url}\" -> \"http://127.0.0.1:{port}\"")
|
| 653 |
server.serve_forever()
|
|
|
|
| 490 |
|
| 491 |
# if __name__ == "__main__":
|
| 492 |
# app.run(host='0.0.0.0', port=7860)
|
| 493 |
+
# from http.server import HTTPServer, SimpleHTTPRequestHandler
|
| 494 |
+
# from pyngrok import ngrok
|
| 495 |
+
# import os
|
| 496 |
+
# from mistralai.client import MistralClient
|
| 497 |
+
# from mistralai.models.chat_completion import ChatMessage
|
| 498 |
+
# import json
|
| 499 |
+
|
| 500 |
+
# # Mistral AI setup
|
| 501 |
+
# api_key = os.getenv("MISTRAL_API_KEY")
|
| 502 |
+
# if not api_key:
|
| 503 |
+
# raise ValueError("MISTRAL_API_KEY environment variable not set")
|
| 504 |
+
|
| 505 |
+
# model = "mistral-tiny"
|
| 506 |
+
# client = MistralClient(api_key=api_key)
|
| 507 |
+
|
| 508 |
+
# def generate_goals(input_var):
|
| 509 |
+
# messages = [
|
| 510 |
+
# 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.")
|
| 511 |
+
# ]
|
| 512 |
+
# try:
|
| 513 |
+
# response = client.chat(model=model, messages=messages)
|
| 514 |
+
# return response.choices[0].message.content
|
| 515 |
+
# except Exception as e:
|
| 516 |
+
# return f"An error occurred: {str(e)}"
|
| 517 |
+
|
| 518 |
+
# html_content = """
|
| 519 |
+
# <!DOCTYPE html>
|
| 520 |
+
# <html lang="en">
|
| 521 |
+
# <head>
|
| 522 |
+
# <meta charset="UTF-8">
|
| 523 |
+
# <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 524 |
+
# <title>Exam Data Analysis Goals Generator</title>
|
| 525 |
+
# <script src="https://d3js.org/d3.v7.min.js"></script>
|
| 526 |
+
# <style>
|
| 527 |
+
# #visualization { width: 100%; height: 600px; border: 1px solid #ccc; }
|
| 528 |
+
# #generatedGoals { margin-top: 20px; padding: 10px; border: 1px solid #ccc; }
|
| 529 |
+
# </style>
|
| 530 |
+
# </head>
|
| 531 |
+
# <body>
|
| 532 |
+
# <h1>Exam Data Analysis Goals Generator</h1>
|
| 533 |
+
# <div id="visualization"></div>
|
| 534 |
+
# <div id="generatedGoals"></div>
|
| 535 |
+
# <script>
|
| 536 |
+
# const width = 1200;
|
| 537 |
+
# const height = 800;
|
| 538 |
+
# const goals = [
|
| 539 |
+
# { 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." },
|
| 540 |
+
# { 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()." },
|
| 541 |
+
# { 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." },
|
| 542 |
+
# { 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." },
|
| 543 |
+
# { 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." },
|
| 544 |
+
# // Add more goals here...
|
| 545 |
+
# ];
|
| 546 |
+
# const connections = [
|
| 547 |
+
# { source: 1, target: 2 },
|
| 548 |
+
# { source: 2, target: 3 },
|
| 549 |
+
# { source: 3, target: 4 },
|
| 550 |
+
# { source: 4, target: 5 },
|
| 551 |
+
# // Add more connections here...
|
| 552 |
+
# ];
|
| 553 |
+
# const svg = d3.select("#visualization")
|
| 554 |
+
# .append("svg")
|
| 555 |
+
# .attr("width", width)
|
| 556 |
+
# .attr("height", height);
|
| 557 |
+
# const simulation = d3.forceSimulation(goals)
|
| 558 |
+
# .force("link", d3.forceLink(connections).id(d => d.id))
|
| 559 |
+
# .force("charge", d3.forceManyBody().strength(-400))
|
| 560 |
+
# .force("center", d3.forceCenter(width / 2, height / 2));
|
| 561 |
+
# const link = svg.append("g")
|
| 562 |
+
# .selectAll("line")
|
| 563 |
+
# .data(connections)
|
| 564 |
+
# .enter().append("line")
|
| 565 |
+
# .attr("stroke", "#999")
|
| 566 |
+
# .attr("stroke-opacity", 0.6);
|
| 567 |
+
# const node = svg.append("g")
|
| 568 |
+
# .selectAll("circle")
|
| 569 |
+
# .data(goals)
|
| 570 |
+
# .enter().append("circle")
|
| 571 |
+
# .attr("r", 10)
|
| 572 |
+
# .attr("fill", d => d.color || "#69b3a2")
|
| 573 |
+
# .call(d3.drag()
|
| 574 |
+
# .on("start", dragstarted)
|
| 575 |
+
# .on("drag", dragged)
|
| 576 |
+
# .on("end", dragended));
|
| 577 |
+
# const text = svg.append("g")
|
| 578 |
+
# .selectAll("text")
|
| 579 |
+
# .data(goals)
|
| 580 |
+
# .enter().append("text")
|
| 581 |
+
# .text(d => d.name)
|
| 582 |
+
# .attr("font-size", "12px")
|
| 583 |
+
# .attr("dx", 12)
|
| 584 |
+
# .attr("dy", 4);
|
| 585 |
+
# node.on("click", async function(event, d) {
|
| 586 |
+
# const response = await fetch('/generate_goals', {
|
| 587 |
+
# method: 'POST',
|
| 588 |
+
# headers: { 'Content-Type': 'application/json' },
|
| 589 |
+
# body: JSON.stringify({ input_var: d.name })
|
| 590 |
+
# });
|
| 591 |
+
# const data = await response.json();
|
| 592 |
+
# document.getElementById("generatedGoals").innerHTML = `<h2>Generated Goals for ${d.name}</h2><pre>${data.goals}</pre>`;
|
| 593 |
+
# });
|
| 594 |
+
# simulation.on("tick", () => {
|
| 595 |
+
# link
|
| 596 |
+
# .attr("x1", d => d.source.x)
|
| 597 |
+
# .attr("y1", d => d.source.y)
|
| 598 |
+
# .attr("x2", d => d.target.x)
|
| 599 |
+
# .attr("y2", d => d.target.y);
|
| 600 |
+
# node
|
| 601 |
+
# .attr("cx", d => d.x)
|
| 602 |
+
# .attr("cy", d => d.y);
|
| 603 |
+
# text
|
| 604 |
+
# .attr("x", d => d.x)
|
| 605 |
+
# .attr("y", d => d.y);
|
| 606 |
+
# });
|
| 607 |
+
# function dragstarted(event) {
|
| 608 |
+
# if (!event.active) simulation.alphaTarget(0.3).restart();
|
| 609 |
+
# event.subject.fx = event.subject.x;
|
| 610 |
+
# event.subject.fy = event.subject.y;
|
| 611 |
+
# }
|
| 612 |
+
# function dragged(event) {
|
| 613 |
+
# event.subject.fx = event.x;
|
| 614 |
+
# event.subject.fy = event.y;
|
| 615 |
+
# }
|
| 616 |
+
# function dragended(event) {
|
| 617 |
+
# if (!event.active) simulation.alphaTarget(0);
|
| 618 |
+
# event.subject.fx = null;
|
| 619 |
+
# event.subject.fy = null;
|
| 620 |
+
# }
|
| 621 |
+
# </script>
|
| 622 |
+
# </body>
|
| 623 |
+
# </html>
|
| 624 |
+
# """
|
| 625 |
+
|
| 626 |
+
# class MyHandler(SimpleHTTPRequestHandler):
|
| 627 |
+
# def do_GET(self):
|
| 628 |
+
# self.send_response(200)
|
| 629 |
+
# self.send_header('Content-type', 'text/html')
|
| 630 |
+
# self.end_headers()
|
| 631 |
+
# self.wfile.write(html_content.encode())
|
| 632 |
+
|
| 633 |
+
# def do_POST(self):
|
| 634 |
+
# if self.path == '/generate_goals':
|
| 635 |
+
# content_length = int(self.headers['Content-Length'])
|
| 636 |
+
# post_data = self.rfile.read(content_length)
|
| 637 |
+
# data = json.loads(post_data.decode('utf-8'))
|
| 638 |
+
# input_var = data['input_var']
|
| 639 |
+
# goals = generate_goals(input_var)
|
| 640 |
+
|
| 641 |
+
# self.send_response(200)
|
| 642 |
+
# self.send_header('Content-type', 'application/json')
|
| 643 |
+
# self.end_headers()
|
| 644 |
+
# self.wfile.write(json.dumps({'goals': goals}).encode())
|
| 645 |
+
# else:
|
| 646 |
+
# self.send_error(404)
|
| 647 |
+
|
| 648 |
+
# if __name__ == '__main__':
|
| 649 |
+
# port = 7860
|
| 650 |
+
# server = HTTPServer(('', port), MyHandler)
|
| 651 |
+
# public_url = ngrok.connect(port).public_url
|
| 652 |
+
# print(f" * ngrok tunnel \"{public_url}\" -> \"http://127.0.0.1:{port}\"")
|
| 653 |
+
# server.serve_forever()
|
| 654 |
+
|
| 655 |
+
# here
|
| 656 |
from http.server import HTTPServer, SimpleHTTPRequestHandler
|
|
|
|
| 657 |
import os
|
| 658 |
from mistralai.client import MistralClient
|
| 659 |
from mistralai.models.chat_completion import ChatMessage
|
|
|
|
| 808 |
self.send_error(404)
|
| 809 |
|
| 810 |
if __name__ == '__main__':
|
| 811 |
+
port = int(os.environ.get("PORT", 7860))
|
| 812 |
+
server = HTTPServer(('0.0.0.0', port), MyHandler)
|
| 813 |
+
print(f"Server running on port {port}")
|
|
|
|
| 814 |
server.serve_forever()
|