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

Hugging Face | 个人使用笔记

一、网站介绍

在这里插入图片描述
模型和数据集都是开源

搜索模型是默认按照趋势排序的

二、模型具体页面

在这里插入图片描述

三、调用API小练习

模型网站:flux-RealismLora
在这里插入图片描述

1.点击View Code 获取参考代码
在这里插入图片描述

2.创建一个python文件复制进一个代码编辑器
注意:需要补充最后一行保存代码
在这里插入图片描述

3.需要获得个人的hugging face的TOKEN
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

headers = {"Authorization": "Bearer hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}中的hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx替换成上面的值

4.保存,运行
得到生成的图片在这里插入图片描述
可能存在Runtime Error的问题,也不是一定会遇到,跟网络状况有关

5.写一个gradio页面,跟这个flux接口对接

# 大模型生成代码
import gradio as gr
import requests
import io
from PIL import ImageAPI_URL = "https://api-inference.huggingface.co/models/XLabs-AI/flux-RealismLora"
headers = {"Authorization": "Bearer hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}def query(prompt):payload = {"inputs": prompt}response = requests.post(API_URL, headers=headers, json=payload, timeout=30, verify=False)if response.status_code == 200:image_bytes = response.contentimage = Image.open(io.BytesIO(image_bytes))return imageelse:return f"Error: {response.status_code} - {response.text}"# Define the Gradio interface without enable_queue
iface = gr.Interface(fn=query,inputs="text",outputs="image",title="Image Generation with Flux Realism Lora",description="Enter a prompt to generate an image using the Flux Realism Lora model."
)# Launch the Gradio app
iface.launch()

网页如图:
在这里插入图片描述
注意: 对于 Hugging Face API:
(1)图像生成模型通常返回图像的二进制数据:
image = Image.open(io.BytesIO(image_bytes)) # 将字节转换为图像
(2)其他类型的模型(如文本生成、情感分析等)可能返回 JSON 格式的响应,其中包含模型输出的详细信息:
json_response = response.json() # 解析 JSON 响应

四、以后补充

个人学习笔记 来源:https://www.bilibili.com/list/watchlater?bvid=BV1Mr4MewEY5&oid=113236728874981在这里插入图片描述


http://www.mrgr.cn/news/60387.html

相关文章:

  • Go 语言结构体
  • SQL Server 当前日期及其未来三天的日期
  • gateway 整合 spring security oauth2
  • 数据库表字段插入bug
  • 二十二、Python基础语法(模块)
  • CSGHub SaaS快速入门指南
  • Node-RED的面板的认识及操作
  • Linux第二讲:Linux权限理解
  • 海南华志亿星电子商务有限公司助力品牌销量飙升
  • 基于 ThinkPHP+Mysql 灵活用工_灵活用工系统_灵活用工平台
  • 通信原理概论复习笔记(2):模拟调制与数字调制
  • Spring Boot实用小技巧8 - 第530篇
  • 北京本盛数字科技有限公司-持续深耕AI智能化健康管理领域
  • nginx------HTTP模块配置详解
  • [论文笔记] 大模型评测:lm-evaluation-harnessPublic(eval-big-refactor)
  • 在 Gitee 或 GitCode 上克隆 Dify 项目源码并启动 Docker 环境
  • C++二级 求每个单词的长度的3种解决办法(包括find、substr)
  • 盛元广通食检中心实验室信息化LIMS系统
  • 大语言模型推理源码解读(基于llama3模型:来源github)
  • 做梦都想拥有的陪伴对象,AI居然免费帮我实现了...文中附送体验地址!
  • autMan奥特曼机器人-内置容器安装依赖报错:externally-managed-environment
  • 深度学习中的损失函数
  • # centos6.5 使用 yum list 报错Error Cannot find a valid baseurl for repo bas 解决方法
  • 3500多万家专利数据存入Mysql数据库
  • 本地服务器上搭建PPTist轻松实现跨地域的在线PPT制作与演示
  • Spring Cloud Alibaba实战入门之Nacos注册中心(四)