当前位置: 首页 > news >正文

asp网站后台管理系统密码破解防盗网站人做清洁

asp网站后台管理系统密码破解,防盗网站人做清洁,好的响应式网站,jspajax网站开发典型实例1. 前言 最近在测试VLM模型#xff0c;发现官方的网页demo#xff0c;代码中视频与图片分辨率可能由于高并发设置的很小#xff0c;导致达不到预期效果#xff0c;于是自己研究了一下#xff0c;搞了一个简单的前端部署#xff0c;自己在服务器部署了下UI界面#xff0…1. 前言 最近在测试VLM模型发现官方的网页demo代码中视频与图片分辨率可能由于高并发设置的很小导致达不到预期效果于是自己研究了一下搞了一个简单的前端部署自己在服务器部署了下UI界面方便在本地笔记本进行测试。 2.代码 import streamlit as st from PIL import Image from transformers import Qwen2VLForConditionalGeneration, AutoProcessor from qwen_vl_utils import process_vision_info import torch import os# 加载模型和处理器 (只加载一次) st.cache_resource # 这个装饰器会缓存模型和处理器 def load_model():model Qwen2VLForConditionalGeneration.from_pretrained(../qwen2_vl/model_7b/, torch_dtypetorch.float16, device_mapauto)processor AutoProcessor.from_pretrained(../qwen2_vl/model_7b/)return model, processor# 加载模型和处理器 model, processor load_model()def load_image(image_file):img Image.open(image_file)return img# Function to load and resize image to fixed height def resize_image_to_height(image, height):# Resize image keeping the aspect ratiowidth int(image.width * height / image.height)return image.resize((width, height))# 处理输入 def process_input(messages):# Preparation for inferencetext processor.apply_chat_template(messages, tokenizeFalse, add_generation_promptTrue)image_inputs, video_inputs process_vision_info(messages)inputs processor(text[text],imagesimage_inputs,videosvideo_inputs,paddingTrue,return_tensorspt,)inputs inputs.to(cuda)# Inferencegenerated_ids model.generate(**inputs, max_new_tokens128)generated_ids_trimmed [out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)]output_text processor.batch_decode(generated_ids_trimmed, skip_special_tokensTrue, clean_up_tokenization_spacesFalse)# Clear all intermediate variables and free GPU memorydel text, image_inputs, video_inputs, inputs, generated_ids, generated_ids_trimmedtorch.cuda.empty_cache()return output_text# Streamlit UI st.title(VLM 视觉内容理解)# 选择文件上传 uploaded_file st.file_uploader(上传图片或视频, type[jpg, jpeg, png, mp4])# 判断文件是否上传 if uploaded_file is not None:# 保存文件到本地upload_dir uploads # 上传文件保存目录if not os.path.exists(upload_dir):os.makedirs(upload_dir)file_path os.path.join(upload_dir, uploaded_file.name)# 保存文件with open(file_path, wb) as f:f.write(uploaded_file.getbuffer())# 判断文件类型if uploaded_file.type.startswith(image):# 加载并显示图片img load_image(file_path)# 设置固定高度fixed_height 300 # 设置固定高度为300px# 调整图片的大小使高度固定宽度按比例调整img_resized resize_image_to_height(img, fixed_height)st.image(img_resized, use_container_widthFalse)# 输入台词部分st.subheader(输入一句提示词)user_input st.text_input(请输入提示词并回车确认)messages [{role: user,content: [{type: image,image: file_path, # 使用本地保存的文件路径max_pixels: 1024 * 960},{type: text, text: user_input},],}]elif uploaded_file.type.startswith(video):# 设置视频固定高度fixed_height 300 # 设置固定高度为300px# 显示视频st.video(file_path)st.subheader(输入一句提示词)user_input st.text_input(请输入提示词并回车确认)# 通过 Markdown 来调整视频的显示样式st.markdown(fstylevideo {{height: {fixed_height}px;width: auto;}}/style,unsafe_allow_htmlTrue)messages [{role: user,content: [{type: video,video: file_path, # 使用本地保存的文件路径max_pixels: 960 * 480,fps: 1.0,},{type: text, text: user_input},],}]# 调用模型进行推理result process_input(messages)if result:# 使用 st.markdown 和 CSS 来自动换行st.markdown(### 模型推理结果)# 将输出格式化为代码块样式并通过 CSS 实现自动换行st.markdown(fpre stylewhite-space: pre-wrap; word-wrap: break-word;{result[0]}/pre,unsafe_allow_htmlTrue)else:st.markdown(### 模型推理结果无结果。)# 推理完成后删除本地文件try:os.remove(file_path)except Exception as e:pass 结论 主要是利用streamlit进行UI的搭建涉及本地文件的上传与下载到服务器中推理完删除。
http://www.dnsts.com.cn/news/203122.html

相关文章:

  • 海南工程建设资料备案网站龙岩网站设计培训
  • 青岛君哲网站建设公司怎么样wordpress 评论栏
  • 优秀集团网站设计百度推广是必须先做网站吗
  • 建设网站的公司专业服务免费开源代码网站
  • 建设部网站有建筑施工分包商标注册查询网址
  • 我公司要网站建设北京网站优化企业
  • 维护网站一年多少钱长沙网站推广平台
  • wordpress 多站点 拷贝微信公众号管理工具
  • 凡科建站模板最好用的wordpress主题
  • 手机网站html5凡科网怎么建网站
  • 北京手机网站建设费用接收外国电视卫星天线
  • 企业网站建设项目计划书成免费crm软件
  • 网站做百度排名教程网络推广计划方案
  • 博罗网站开发vi企业形象设计是什么
  • 西安seo网站推广优化网站开发配置
  • 装修网站建设优缺点sem分析是什么意思
  • 手机建网站教程中国做外贸网站
  • wap手机网站尺寸凡科免费网站建设
  • 网站 预算做网站换服务器怎么整
  • 吉安网站建设吉安番禺五屏网站建设
  • 哪些网站可以看一级a做爰片色系网站的
  • wordpress资源站模板爱站网功能
  • 建网站维护需要多少钱渝快办官网
  • 义乌市评建设职称网站做网站需要注意什么问题
  • php做网站有哪些优点网站开发设计内容
  • 北京搜索优化推广公司石家庄搜索引擎优化
  • 网站建设 价格低wordpress 经过天数
  • 用视频做网站背景彭水网站建设
  • 江西泰飞建设有限公司网站陕西优秀的企业门户网站建设
  • php网站登录系统怎么做做网站的前途怎么样