Flask应用的部署和使用,以照片分割为例。

任务是本地上传一张照片,在服务器端处理后,下载到本地。

服务器端已经封装好了相关的程序通过以下语句调用

from amg_test import main
from test import test
main()
test()

首先要在虚拟环境中安装flask

pip install Flask

 文件组织架构

your_project/
│
├── app.py
├── templates/
│   └── download.html
└── uploads/

templates里面是上传、下载时的网页渲染文件

app.py

from flask import Flask, render_template, request, send_from_directory
from amg_test import main
from test import test
import osapp = Flask(__name__)# 设置一个允许上传的文件类型
ALLOWED_EXTENSIONS = {'png', 'jpg'}# 检查文件类型是否在允许的范围内
def allowed_file(filename):return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS# 上传文件的路由
@app.route('/upload', methods=['GET', 'POST'])
def upload_file():if request.method == 'POST':# 检查是否有文件被上传if 'file' not in request.files:return 'No file part'file = request.files['file']# 如果用户没有选择文件,浏览器也会发送一个空的文件名if file.filename == '':return 'No selected file'# 检查文件类型是否合法if file and allowed_file(file.filename):# 保存上传的文件到服务器的 uploads 文件夹下file_path = os.path.join('./data/original', file.filename)file.save(file_path)return render_template('download.html', filename=file.filename)else:return 'File type not allowed'return render_template('upload.html')# 提供下载处理后的照片的路由
@app.route('/download/<filename>')
def download_file(filename):main()test()return send_from_directory('./data/result', filename, as_attachment=True)if __name__ == '__main__':app.run(host='0.0.0.0', port='5000', debug=True)
# 使用通配符IP地址:0.0.0.0

参考:Flask app的run配置IP\PORT远程访问_flask port-CSDN博客

 upload.html

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Upload File</title>
</head>
<body><h1>Upload a File</h1><form method="POST" enctype="multipart/form-data"><input type="file" name="file"><input type="submit" value="Upload"></form>
</body>
</html>

download.html

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Download File</title>
</head>
<body><h1>File uploaded successfully</h1><p><a href="{{ url_for('download_file', filename=filename) }}">Download processed photo</a></p>
</body>
</html>

结果展示

首先要在服务器端(内网地址:10.28.220.198)运行app.py

2024-05-06 18:03:00.163456: I external/local_tsl/tsl/cuda/cudart_stub.cc:31] Could not find cuda drivers on your machine, GPU will not be used.
2024-05-06 18:03:00.184021: E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:9261] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered
2024-05-06 18:03:00.184043: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:607] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered
2024-05-06 18:03:00.184679: E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1515] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
2024-05-06 18:03:00.188218: I external/local_tsl/tsl/cuda/cudart_stub.cc:31] Could not find cuda drivers on your machine, GPU will not be used.
2024-05-06 18:03:00.188374: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
2024-05-06 18:03:00.777609: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT
WARNING:tensorflow:From /home/huanglu/anaconda3/envs/segment-system/lib/python3.10/site-packages/tensorflow/python/compat/v2_compat.py:108: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.
Instructions for updating:
non-resource variables are not supported in the long term
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.* Running on all addresses (0.0.0.0)* Running on http://127.0.0.1:5000* Running on http://10.28.220.198:5000
Press CTRL+C to quit* Restarting with stat* Serving Flask app 'app'* Debug mode: on
2024-05-06 18:03:02.270099: I external/local_tsl/tsl/cuda/cudart_stub.cc:31] Could not find cuda drivers on your machine, GPU will not be used.
2024-05-06 18:03:02.291600: E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:9261] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered
2024-05-06 18:03:02.291625: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:607] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered
2024-05-06 18:03:02.292204: E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1515] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
2024-05-06 18:03:02.295947: I external/local_tsl/tsl/cuda/cudart_stub.cc:31] Could not find cuda drivers on your machine, GPU will not be used.
2024-05-06 18:03:02.296127: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
2024-05-06 18:03:02.905518: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT
WARNING:tensorflow:From /home/huanglu/anaconda3/envs/segment-system/lib/python3.10/site-packages/tensorflow/python/compat/v2_compat.py:108: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.
Instructions for updating:
non-resource variables are not supported in the long term* Debugger is active!* Debugger PIN: 157-069-259

本地计算机打开浏览器,访问http://10.28.220.198:5000/upload

注意没有s,是http

 上传一张照片

点击下载,由于是在下载函数里面处理照片,所以会比较慢

结果和原图是组里的涉密文件,不能展示。

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/7042.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

基于Spring Boot的民宿管理平台设计与实现

基于Spring Boot的民宿管理平台设计与实现 开发语言&#xff1a;Java框架&#xff1a;springbootJDK版本&#xff1a;JDK1.8数据库工具&#xff1a;Navicat11开发软件&#xff1a;eclipse/myeclipse/idea 系统部分展示 前台首页功能界面图&#xff0c;在系统首页可以查看首页…

【软件开发规范篇】JAVA后端开发编程规范

作者介绍&#xff1a;本人笔名姑苏老陈&#xff0c;从事JAVA开发工作十多年了&#xff0c;带过大学刚毕业的实习生&#xff0c;也带过技术团队。最近有个朋友的表弟&#xff0c;马上要大学毕业了&#xff0c;想从事JAVA开发工作&#xff0c;但不知道从何处入手。于是&#xff0…

视频号小店在行业内的门槛高不高?有门槛是好事还是坏事?

大家好&#xff0c;我是电商小V 现在伴随着时代的慢慢发展&#xff0c;很多人都是想找一个好一点的创业项目&#xff0c;现在找创业项目都是找一些稍微有门槛的项目&#xff0c;没有门槛的话&#xff0c;要不然刚开始去做&#xff0c;项目就泛滥了&#xff0c;项目的红利期直接…

【AI】深度学习框架的期望与现实 机器学习编译尚未兑现其早期的一些承诺……

深度学习框架的期望与现实 机器学习编译尚未兑现其早期的一些承诺…… 来自&#xff1a;Axelera AI 资深软件工程师 Matthew Barrett 原帖是linkedin帖子&#xff1a; https://linkedin.com/posts/matthew-barrett-a49929177_i-think-its-fair-to-say-that-ml-compilation-ac…

Python_4-远程连接Linux

文章目录 使用Python通过SSH自动化Linux主机管理代码执行ls结果&#xff1a;文件传输&#xff1a; 使用Python通过SSH自动化Linux主机管理 在系统管理与自动化运维中&#xff0c;SSH&#xff08;Secure Shell&#xff09;是一个常用的协议&#xff0c;用于安全地访问远程计算机…

FTP协议与工作原理

一、FTP协议 FTP&#xff08;FileTransferProtocol&#xff09;文件传输协议&#xff1a;用于Internet上的控制文件的双向传输&#xff0c;是一个应用程序&#xff08;Application&#xff09;。基于不同的操作系统有不同的FTP应用程序&#xff0c;而所有这些应用程序都遵守同…

怎么给word文件名批量替换部分文字?word设置批量替换文字教程

批量替换Word文件名中的几个字&#xff0c;对于经常处理大量文件的人来说&#xff0c;是一项非常实用的技能。以下是一个详细的步骤指南&#xff0c;帮助你快速完成这项任务。 首先&#xff0c;你需要准备一个可以批量重命名文件的工具。市面上有很多这样的工具可供选择&#x…

win10禁止自动更新的终极方法

添加注册表值 1.运行&#xff0c;输入regedit 2.打开注册表编辑器依次进入以下路径“计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings”。 3.在Settings项中&#xff0c;新建DWORD&#xff08;32位&#xff09;值(D)&#xff0c;重命名为以下命名“Fl…

easy_ssti_ctfshow_2023愚人杯

https://ctf.show/challenges#easy_ssti-3969 2023愚人杯有提示app.zip&#xff0c;访问 https://1f660587-5340-4b20-b929-c4549d9a5d4b.challenge.ctf.show/app.zip得到压缩包&#xff0c;拿到一个py文件 可以看到参数名是name&#xff0c;对参数进行筛选&#xff0c;包含ge…

《Fundamentals of Power Electronics》——脉宽调制器建模

下图给出了一个简单脉宽调制器电路的原理图。 脉宽调制器电路产生一个用于指令转换器功率管导通和关断的逻辑信号δ(t)。该逻辑信号δ(t)是周期性的&#xff0c;其频率为fs&#xff0c;占空比为d(t)。脉宽调制器的输入是一个模拟控制信号vc(t)。脉宽调制器的作用是产生一个与模…

生产管理驾驶舱模板分享,制造业都来抄作业!

今天要讲的是一张从组织、生产车间、物料、仓库、时间等不同维度&#xff0c;展示产能、产量、投入成本、产能达成率等关键信息&#xff0c;让企业运营决策者全面了解生产产能情况、产量情况、投入成本情况、产能达成率情况的BI生产管理驾驶舱模板。这是奥威BI标准方案为设有生…

问题管理员的工作角色、职责和技能

问题管理就是识别、分析和解决反复出现的根本原因问题并永久修复它们。听起来很简单对吧&#xff0c;不幸的是&#xff0c;情况并非总是如此。对于组织来说&#xff0c;IT问题管理一直是一门棘手的 ITSM 学科。一个经常被忽视的关键因素是有效的问题 管理不仅仅是工具和流程。 …

Swagger使用和注释介绍

一&#xff1a;介绍 1、什么是Swagger Swagger是一个规范和完整的框架&#xff0c;用于生成、描述、调用和可视化 RESTful 风格的 Web 服务。总体目标是使客户端和文件系统作为服务器以同样的速度来更新。文件的方法&#xff0c;参数和模型紧密集成到服务器端的代码&#xff…

karateclub,一个超酷的 Python 库!

更多资料获取 &#x1f4da; 个人网站&#xff1a;ipengtao.com 大家好&#xff0c;今天为大家分享一个超酷的 Python 库 - karateclub。 Github地址&#xff1a;https://github.com/benedekrozemberczki/karateclub Python karateclub是一个用于图嵌入和图聚类的库&#xff…

Springboot+mybatis升级版(Postman测试)

一、项目结构 1.导入依赖 <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/POM/4.0.0"xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation"http://maven.apach…

平面分割--------PCL

平面分割 bool PclTool::planeSegmentation(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud, pcl::ModelCoefficients::Ptr coefficients, pcl::PointIndices::Ptr inliers) {std::cout << "Point cloud data: " << cloud->points.size() <<…

8.【Orangepi Zero2】UDEV的配置文件,自动挂载U盘

8.UDEV的配置文件&#xff0c;自动挂载U盘 UDEV的配置文件udev 规则的匹配键挂载U盘手动挂载U盘自动挂载usbpan.rules tree命令 UDEV的配置文件 参考文章&#xff1a;Linux 基础 – udev 和 rules 使用规则5 规则文件是 udev 里最重要的部分&#xff0c;默认是存放在 /etc/ud…

CVE-2019-19945漏洞复现 Openwrt针对uhttpd漏洞利用

根据官方漏洞的文档&#xff0c;该漏洞的复现工作我会基于openwrt的18.06.4这个版本进行测试。我选取的环境是渗透测试常用的kali-Linux系统&#xff0c;然后在其中搭建docker环境来完成相应的实验环境的部署。我通过这个核心命令获取docker环境&#xff1a; sudo docker impo…

微信答题链接怎么做_新手也能快速上手制作

在数字营销日新月异的今天&#xff0c;如何有效吸引用户参与、提升品牌曝光度&#xff0c;成为了每一个营销人都在思考的问题。而微信答题链接&#xff0c;作为一种新兴的互动营销方式&#xff0c;正以其独特的魅力&#xff0c;在营销界掀起一股新的热潮。今天&#xff0c;就让…

从C向C++16——常见容器2

一.stack容器 1.stack理解 概念&#xff1a; stack是一种先进后出的数据结构&#xff0c;它只有一个出口。 它在C中也叫栈&#xff0c;类似于我们在《数据结构和算法》里面的栈&#xff0c;只不过在C中把其封装成库&#xff0c;我们可以直接使用。 注意&#xff1a;栈中只有…