Spaces:
Paused
Paused
Update app.py
Browse files284 unmodified lines2852862872882892902912922932942952961 unmodified line298299300301302303304305306307308309310311312313314315316317193 unmodified lines511512513514515516517518519520521522523524525284 unmodified lines# if __name__ == "__main__":# iface.launch()from flask import Flask, request, jsonify, render_template_stringimport osfrom mistralai.client import MistralClientfrom mistralai.models.chat_completion import ChatMessage# Ensure the environment variable for the API key is setapi_key = os.getenv("MISTRAL_API_KEY")if not api_key:raise ValueError("MISTRAL_API_KEY environment variable not set")1 unmodified linemodel = "mistral-tiny"client = MistralClient(api_key=api_key)app = Flask(__name__)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)content = response.choices[0].message.contentreturn contentexcept Exception as e:return f"An error occurred: {str(e)}"# HTML content with interactive visualizationhtml_content = """<!DOCTYPE html>193 unmodified lines</html>"""@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=5000, debug=True)284 unmodified lines2852862872882892902912922932942952961 unmodified line298299300301302303304305306307308309310311312313314193 unmodified lines508509510511512513514515516517518519520521522284 unmodified lines# if __name__ == "__main__":# iface.launch()import gradio as grimport osfrom mistralai.client import MistralClientfrom mistralai.models.chat_completion import ChatMessage# Mistral AI setupapi_key = os.getenv("MISTRAL_API_KEY")if not api_key:raise ValueError("MISTRAL_API_KEY environment variable not set")1 unmodified linemodel = "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.contentexcept Exception as e:return f"An error occurred: {str(e)}"# HTML content with interactive visualizationhtml_content = """<!DOCTYPE html>193 unmodified lines</html>"""# Gradio interfaceiface = gr.Interface(fn=generate_goals,inputs="text",outputs="text",title="Exam Data Analysis Goals Generator",description="Click on a goal in the visualization to generate related goals.",article=html_content)# Launch the Gradio appiface.launch()
app.py+15-18