Flask是一个用于使用Python开发Web应用程序的轻量级框架。
I当前正在使用一个小型Web界面,该界面允许不同的用户上传文件,转换他们已上传的文件并下载转换后的文件。转换的细节A ...
i当前正在使用烧瓶 - uploads来管理上传的文件,我将它们存储在文件系统中。用户上传并转换文件后,都会有各种删除文件的漂亮按钮,以使上传文件夹不会填充。
我如何将CSRF令牌存储在我的前端nextjs标题中。我将我的JWT令牌存储在cookie
在我的nextjs中,我的标题是
(使用烧瓶,jinja2,css)我想将jinja占位符放入指向我的CSS样式表的链接中,以便我将在所有页面上应用一个基本样式,并为每个页面应用独特的样式表...
@app.route('/login', methods=["GET", "POST"]) def login(): email = request.form.get("email") password = request.form.get("password") if request.method == "POST": user = User.query.filter_by(email=email).first() if not user: flash("sorry that email doesn't exist") return redirect(url_for('login')) elif not check_password_hash(user.password, password): flash("Password incorrect, please try again") return redirect(url_for('login')) else: login_user(user) return redirect(url_for('secrets', id=user.id)) return render_template("login.html")
luntimeError:安装带有“ async”额外的烧瓶以使用异步视图
当我尝试使用Docker Run(本地)在本地运行此问题时,我将在下面遇到错误。但是,我已经运行了“ pip install”烧瓶[async]”,并且一切似乎都安装了,b ...
为什么我的文件上传到github时我的文件不正常?它们在IDE的当地烧瓶中正常工作。 尽管如果结构与TH ...
from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello, World!' if __name__ == '__main__': app.run(debug=True, port=8000, host='0.0.0.0') * Running on http://0.0.0.0:8000/ (Press CTRL+C to quit) * Restarting with stat /Library/Frameworks/Python.framework/Versions/3.4/bin/python3: can't find '__main__' module in ''
如何在Python烧瓶应用程序中使用Redis队列(RQ)工人进行背景作业?
将Redis队列(RQ)集成到烧瓶应用程序以处理背景任务的步骤是什么? 特别是,我需要以下帮助:
Error处理请求:400请求在烧瓶中包含一个无效的参数 我正在尝试在烧瓶应用程序中使用微调的Gemini模型,但是在运行该应用程序后会遇到此错误:“错误处理请求:400请求包含无效的参数。”
# app.py from flask import Flask, render_template, request, jsonify from dotenv import load_dotenv import os import utils # Import utility functions import vertexai from vertexai.generative_models import GenerativeModel app = Flask(__name__) load_dotenv() # Load environment variables from .env file print(f"GOOGLE_APPLICATION_CREDENTIALS: {os.environ.get('GOOGLE_APPLICATION_CREDENTIALS')}") # Load the model and environment variables PROJECT_ID = os.getenv('PROJECT_ID') LOCATION = os.getenv('LOCATION') MODEL_NAME = os.getenv('MODEL_NAME') # Load from .env # Initialize Vertex AI vertexai.init(project=PROJECT_ID, location=LOCATION) # Load the fine-tuned model - adjust this part model = GenerativeModel(MODEL_NAME) UPLOAD_FOLDER = 'D:/University of Law/Courses/MSc CS Final Project/AI_Powered_Blueprint_Analyzer/uploads' os.makedirs(UPLOAD_FOLDER, exist_ok=True) app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER @app.route("/", methods=["GET", "POST"]) def index(): if request.method == "POST": try: analysis_name = request.form.get("analysis_name") blueprint_file = request.files.get("blueprint") additional_data = { "persona": request.files.get("persona"), "kpis": request.files.get("kpis"), "stakeholder_maps": request.files.get("stakeholder_maps"), "system_map": request.files.get("system_map"), "user_journey_map": request.files.get("user_journey_map"), "project_roadmap": request.files.get("project_roadmap"), } # validate required files if not blueprint_file: return render_template("index.html", error="Blueprint file is required") prompt = utils.construct_prompt(analysis_name, blueprint_file, additional_data, app.config['UPLOAD_FOLDER']) print("Generated Prompt:", prompt) # Debug print response = model.generate_content( contents=prompt, generation_config={ "max_output_tokens": 2048, "temperature": 0.7, "top_p": 0.8, } ) if response and response.text: swot_analysis, improvements = utils.parse_gemini_response(response.text) return render_template("results.html", analysis_name=analysis_name, swot=swot_analysis, improvements=improvements) else: return render_template("index.html", error="No response generated from the model") except Exception as e: print(f"Full error details: {str(e)}") # Debug print return render_template("index.html", error=f"Error processing request: {str(e)}") return render_template("index.html") if __name__ == "__main__": app.run(debug=True) # utils.py import os import re from werkzeug.utils import secure_filename def allowed_file(filename): allowed_extensions = {'png', 'jpg', 'jpeg', 'pdf', 'txt'} return '.' in filename and filename.rsplit('.', 1)[1].lower() in allowed_extensions def construct_prompt(analysis_name, blueprint_file, additional_data, upload_folder): prompt = f"Analysis Name: {analysis_name}\n\n" def read_file_content(file): file_content = file.read() file.seek(0) # Reset file pointer try: return file_content.decode('utf-8') except UnicodeDecodeError: return "[Binary file content not included in analysis]" if blueprint_file: filename = secure_filename(blueprint_file.filename) filepath = os.path.join(upload_folder, filename) blueprint_file.save(filepath) prompt += f"Blueprint File: {filename}\n" prompt += read_file_content(blueprint_file) + "\n\n" for data_type, file in additional_data.items(): if file: filename = secure_filename(file.filename) filepath = os.path.join(upload_folder, filename) file.save(filepath) prompt += f"{data_type.capitalize()} Content:\n" # Process file content if needed prompt += read_file_content(file) + "\n\n" prompt += """ Please analyze the provided service blueprint and additional materials. Structure your response as follows: SWOT Analysis: - Strengths: [List key strengths identified in the blueprint] - Weaknesses: [List key weaknesses identified in the blueprint] - Opportunities: [List key opportunities identified in the blueprint] - Threats: [List key threats identified in the blueprint] Improvements: 1. [First improvement with detailed steps] 2. [Second improvement with detailed steps] [Continue with numbered improvements as needed] """ return prompt def parse_gemini_response(response_text): #Improved parsing logic using regex swot_match = re.search(r"SWOT Analysis:\n(.*?)\nImprovements:", response_text, re.DOTALL) improvements_match = re.search(r"Improvements:\n(.*?)$", response_text, re.DOTALL) swot_analysis = swot_match.group(1).strip() if swot_match else "SWOT analysis not found." improvements = improvements_match.group(1).strip() if improvements_match else "Improvements not found." return swot_analysis, improvements