# import gradio as gr
# import os
# from mistralai.client import MistralClient
# from mistralai.models.chat_completion import ChatMessage
# # Ensure the environment variable for the API key is set
# api_key = os.getenv("MISTRAL_API_KEY")
# if not api_key:
# raise ValueError("MISTRAL_API_KEY environment variable not set")
# model = "mistral-tiny"
# client = MistralClient(api_key=api_key)
# def generate_goals(input_var):
# messages = [
# 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")
# ]
# try:
# response = client.chat(model=model, messages=messages)
# content = response.choices[0].message.content
# return content
# except Exception as e:
# return f"An error occurred: {str(e)}"
# # HTML content
# html_content = """
#
#
#
#
#
# Comprehensive Exam Data Analysis with Pandas - 30 Industry Goals with Connections
#
#
#
#
# Comprehensive Exam Data Analysis with Pandas - 30 Industry Goals with Connections
#
#
#
#
#
#
#
#
# """
# # Gradio interface
# iface = gr.Interface(
# fn=generate_goals,
# inputs=gr.Textbox(label="Goal Name"),
# outputs=gr.Textbox(label="Generated Goals"),
# title="Exam Data Analysis Goals Generator",
# description="Click on a goal in the visualization to generate related goals.",
# allow_flagging="never",
# theme="default",
# css=html_content
# )
# if __name__ == "__main__":
# iface.launch()
# from flask import Flask, request, jsonify, render_template_string
# import os
# from mistralai.client import MistralClient
# from mistralai.models.chat_completion import ChatMessage
# app = Flask(__name__)
# # Mistral AI setup
# api_key = os.getenv("MISTRAL_API_KEY")
# if not api_key:
# raise ValueError("MISTRAL_API_KEY environment variable not set")
# model = "mistral-tiny"
# client = MistralClient(api_key=api_key)
# def generate_goals(input_var):
# messages = [
# 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.")
# ]
# try:
# response = client.chat(model=model, messages=messages)
# return response.choices[0].message.content
# except Exception as e:
# return f"An error occurred: {str(e)}"
# html_content = """
#
#
#
#
#
# Exam Data Analysis Goals Generator
#
#
#
#
# Exam Data Analysis Goals Generator
#
#
#
#
#
# """
# @app.route('/')
# def index():
# return render_template_string(html_content)
# @app.route('/generate_goals', methods=['POST'])
# def generate_goals_api():
# input_var = request.json['input_var']
# goals = generate_goals(input_var)
# return jsonify({'goals': goals})
# if __name__ == "__main__":
# app.run(host='0.0.0.0', port=7860)
from http.server import HTTPServer, SimpleHTTPRequestHandler
from pyngrok import ngrok
import os
from mistralai.client import MistralClient
from mistralai.models.chat_completion import ChatMessage
import json
# Mistral AI setup
api_key = os.getenv("MISTRAL_API_KEY")
if not api_key:
raise ValueError("MISTRAL_API_KEY environment variable not set")
model = "mistral-tiny"
client = MistralClient(api_key=api_key)
def generate_goals(input_var):
messages = [
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.")
]
try:
response = client.chat(model=model, messages=messages)
return response.choices[0].message.content
except Exception as e:
return f"An error occurred: {str(e)}"
html_content = """
Exam Data Analysis Goals Generator
Exam Data Analysis Goals Generator
"""
class MyHandler(SimpleHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write(html_content.encode())
def do_POST(self):
if self.path == '/generate_goals':
content_length = int(self.headers['Content-Length'])
post_data = self.rfile.read(content_length)
data = json.loads(post_data.decode('utf-8'))
input_var = data['input_var']
goals = generate_goals(input_var)
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
self.wfile.write(json.dumps({'goals': goals}).encode())
else:
self.send_error(404)
if __name__ == '__main__':
port = 7860
server = HTTPServer(('', port), MyHandler)
public_url = ngrok.connect(port).public_url
print(f" * ngrok tunnel \"{public_url}\" -> \"http://127.0.0.1:{port}\"")
server.serve_forever()