首页 > 其他分享 >文生图买不起,试试用必应的bing搜索图片服务

文生图买不起,试试用必应的bing搜索图片服务

时间:2024-03-13 15:32:59浏览次数:22  
标签:search cn 文生 bing https 必应 com response

首先需要一个API key,可以在这里先登录:

Microsoft Azure

然后创建资源 – > 搜索 bing serach --> 选择 bing search v7

定价层选F1,每月有1000的额度,注意勾选最后的(我确认本人已阅读并理解下面的声明。)

审阅并创建后,会跳转到该资源,如果以后要查看该资源,在主页(Microsoft Azure)可以看到资源列表。

点开这个搜索资源,页面里有示例代码:

#Copyright (c) Microsoft Corporation. All rights reserved.
#Licensed under the MIT License.

# -*- coding: utf-8 -*-

import json
import os 
from pprint import pprint
import requests

'''
This sample makes a call to the Bing Web Search API with a query and returns relevant web search.
Documentation: https://docs.microsoft.com/en-us/bing/search-apis/bing-web-search/overview
'''

# Add your Bing Search V7 subscription key and endpoint to your environment variables.
subscription_key = os.environ['BING_SEARCH_V7_SUBSCRIPTION_KEY']
endpoint = os.environ['BING_SEARCH_V7_ENDPOINT'] + "/bing/v7.0/search"

# Query term(s) to search for. 
query = "Microsoft"

# Construct a request
mkt = 'en-US'
params = { 'q': query, 'mkt': mkt }
headers = { 'Ocp-Apim-Subscription-Key': subscription_key }

# Call the API
try:
    response = requests.get(endpoint, headers=headers, params=params)
    response.raise_for_status()

    print("
Headers:
")
    print(response.headers)

    print("
JSON Response:
")
    pprint(response.json())
except Exception as ex:
    raise ex

把endpoint改为:

"https://api.bing.microsoft.com/v7.0/images/search"

subscription_key改为页面中可以点开看到的key,不过程序有小点错误。

mkt改为zh-CN,代码可参考(Market and language codes used by the Bing Visual Search API - Bing Services | Microsoft Learn

query 改为 "刺客+月光下",按这个搜索

过滤条件,只要横幅的图片,高分辨率

'minWidth':1280,

'maxHeight':1280,

'minHeight':640

最后把返回存为json文件:

with open(file='image_list.json',mode="w",encoding="utf-8") as f:

f.write(str(response.text))

请求结果,总共544条命中,可以看出宽高都满足要求:

	
_type	"Images"
instrumentation	
_type	"ResponseInstrumentation"
readLink	"images/search?q=刺客+月光下"
webSearchUrl	"https://www.bing.com/images/search?q=刺客+月光下&FORM=OIIARP"
queryContext	
originalQuery	"刺客+月光下"
alterationDisplayQuery	"刺客+月光下"
alterationOverrideQuery	"+刺客+月光下"
alterationMethod	"AM_JustChangeIt"
alterationType	"CombinedAlterationsChained"
totalEstimatedMatches	544
nextOffset	30
currentOffset	0
value	
0	
webSearchUrl	"https://www.bing.com/images/search?view=detailv2&FORM=OIIRPO&q=%E5%88%BA%E5%AE%A2%2b%E6%9C%88%E5%85%89%E4%B8%8B&id=CBC7F6C635655098200110CF78C28BB3EC2DE70C&simid=608025927915498584"
name	"刺客|插画|游戏原画|SI__YUAN - 原创作品 - 站酷 (ZCOOL)"
thumbnailUrl	"https://ts2.cn.mm.bing.net/th?id=OIP-C.YLlAnPrEer2IRDJ5AWZ6AwHaEc&pid=Api"
datePublished	"2020-09-03T23:00:00.0000000Z"
isFamilyFriendly	true
contentUrl	"https://img.zcool.cn/community/0138495ba75e5aa8012099c807c5d9.jpg@1280w_1l_2o_100sh.jpg"
hostPageUrl	"https://www.zcool.com.cn/work/ZMzAzODYzODg=.html"
contentSize	"411352 B"
encodingFormat	"jpeg"
hostPageDisplayUrl	"https://www.zcool.com.cn/work/ZMzAzODYzODg=.html"
width	1280
height	768
hostPageFavIconUrl	"https://www.bing.com/th?id=ODF.JEyGtERG1FO2k2Kl-ibPdA&pid=Api"
hostPageDiscoveredDate	"2018-10-17T00:00:00.0000000Z"
isTransparent	false
thumbnail	
width	474
height	284
imageInsightsToken	"ccid_YLlAnPrE*cp_C745C2185F7E74C4C8A62D6AEB61977C*mid_CBC7F6C635655098200110CF78C28BB3EC2DE70C*simid_608025927915498584*thid_OIP.YLlAnPrEer2IRDJ5AWZ6AwHaEc"
insightsMetadata	
pagesIncludingCount	4
availableSizesCount	3
imageId	"CBC7F6C635655098200110CF78C28BB3EC2DE70C"
accentColor	"AE9B1D"
1	
webSearchUrl	"https://www.bing.com/images/search?view=detailv2&FORM=OIIRPO&q=%E5%88%BA%E5%AE%A2%2b%E6%9C%88%E5%85%89%E4%B8%8B&id=74335DBDE7128047E252B596CC3AD88972B5214C&simid=608018798297695190"
name	"刺客|插画|概念设定|fengweic12 - 原创作品 - 站酷 (ZCOOL)"
thumbnailUrl	"https://ts4.cn.mm.bing.net/th?id=OIP-C.sO9BRnNrkfQB8k718Y4U5AHaEo&pid=Api"
datePublished	"2021-08-02T14:30:00.0000000Z"
isFamilyFriendly	true
contentUrl	"https://img.zcool.cn/community/01aada554953e70000019ae91b9012.jpg@1280w_1l_2o_100sh.jpg"
hostPageUrl	"https://www.zcool.com.cn/work/ZNjQ0NTEy.html"
contentSize	"420890 B"
encodingFormat	"jpeg"
hostPageDisplayUrl	"https://www.zcool.com.cn/work/ZNjQ0NTEy.html"
width	1280
height	800
hostPageFavIconUrl	"https://www.bing.com/th?id=ODF.JEyGtERG1FO2k2Kl-ibPdA&pid=Api"
hostPageDiscoveredDate	"2018-11-12T00:00:00.0000000Z"
isTransparent	false
thumbnail	
width	474
height	296
imageInsightsToken	"ccid_sO9BRnNr*cp_0CDEE98093951038C22771FF502ADAB0*mid_74335DBDE7128047E252B596CC3AD88972B5214C*simid_608018798297695190*thid_OIP.sO9BRnNrkfQB8k718Y4U5AHaEo"
insightsMetadata	
pagesIncludingCount	1
availableSizesCount	1
imageId	"74335DBDE7128047E252B596CC3AD88972B5214C"
accentColor	"2597A6"
2	
webSearchUrl	"https://www.bing.com/images/search?view=detailv2&FORM=OIIRPO&q=%E5%88%BA%E5%AE%A2%2b%E6%9C%88%E5%85%89%E4%B8%8B&id=2C8A3040C263BB0C8A935325E85838D8A928857F&simid=608023226415787705"
name	"《刺客信条4》壁纸11_游戏新闻__单机游戏_新浪游戏_新浪网"
thumbnailUrl	"https://ts4.cn.mm.bing.net/th?id=OIP-C.tA3NGAvNWkDVRyYZrP6W0gHaEK&pid=Api"
datePublished	"2013-09-01T14:50:00.0000000Z"
isFamilyFriendly	true
contentUrl	"http://i1.sinaimg.cn/gm/j/i/2013-07-31/U4341P115T41D243969F757DT20130731151822.jpg"
hostPageUrl	"http://games.sina.com.cn/j/i/2013-07-31/1518243969.shtml"
contentSize	"679314 B"
encodingFormat	"jpeg"
hostPageDisplayUrl	"games.sina.com.cn/j/i/2013-07-31/1518243969.shtml"
width	1920
height	1080
hostPageFavIconUrl	"https://www.bing.com/th?id=ODF.9HJur1uaiYYuDkDT1cIQZQ&pid=Api"
hostPageDomainFriendlyName	"新浪网"
hostPageDiscoveredDate	"2013-09-01T14:50:00.0000000Z"
isTransparent	false
thumbnail	
width	474
height	266
imageInsightsToken	"ccid_tA3NGAvN*cp_721E22113F2571D0366D91CD1BED4982*mid_2C8A3040C263BB0C8A935325E85838D8A928857F*simid_608023226415787705*thid_OIP.tA3NGAvNWkDVRyYZrP6W0gHaEK"
insightsMetadata	
pagesIncludingCount	37
availableSizesCount	10
imageId	"2C8A3040C263BB0C8A935325E85838D8A928857F"
accentColor	"348397"

下载前面几个看看内容,好像没有月光,这个要怪bing:

再试试query = "月光下+刺客",结果有点区别:

改进后的示例代码,未封装:

#Copyright (c) Microsoft Corporation. All rights reserved.
#Licensed under the MIT License.

# -*- coding: utf-8 -*-

import json
import os 
from pprint import pprint
import requests

'''
This sample makes a call to the Bing Web Search API with a query and returns relevant web search.
Documentation: https://docs.microsoft.com/en-us/bing/search-apis/bing-web-search/overview
'''

# Add your Bing Search V7 subscription key and endpoint to your environment variables.
subscription_key = "YOURKEY"
endpoint = "https://api.bing.microsoft.com/v7.0/images/search"

# Query term(s) to search for. 
query = "刺客+月光下"

# Construct a request
mkt = 'zh-CN'    #'en-US'
params = { 'q': query,
            'mkt': mkt,
            'count':30,
            'minWidth':1280,
            'maxHeight':1280,
            'minHeight':640 }
headers = { 'Ocp-Apim-Subscription-Key': subscription_key }

# Call the API
try:
    response = requests.get(endpoint, headers=headers, params=params)
    response.raise_for_status()

    print("Headers:")
    print(response.headers)

    print("JSON Response:")
    pprint(response.json())
    print(response.text)
    with open(file='image_list.json',mode="w",encoding="utf-8") as f:
        f.write(str(response.text))
except Exception as ex:
    raise ex

标签:search,cn,文生,bing,https,必应,com,response
From: https://blog.csdn.net/cnnews/article/details/136677298

相关文章

  • 教程|腾讯云HAI搭建一个Stable Diffusion 文生图应用
    本次我们使用腾讯云高性能应用服务HAI体验快速搭建并使用AI模型StableDiffusion进行文生图推理,实现思路如下:体验高性能应用服务HAI一键部署StableDiffusionAIGC。启动StableDiffusionWebUI进行文生图模型推理。操作步骤步骤1:创建高性能应用服务1.登录......
  • 免费网站统计工具,可统计百度、必应、搜狗、360来源搜索词
    统计鸟官网地址:https://www.tongjiniao.com/站长必备!网站数据统计,流量监测平台提供网站数据统计分析、搜索关键词、流量访问来源等服务深入分析用户点击习惯,为智能化运营网站提供更好的用户体验 目录一、注册账号信息二、添加站点信息三、放置统计代码四、查看统计信息......
  • 微软曾想将 Bing 搜索卖给苹果;英伟达首次公开将华为列为对手丨 RTE 开发者日报 Vol.15
       开发者朋友们大家好: 这里是「RTE开发者日报」,每天和大家一起看新闻、聊八卦。我们的社区编辑团队会整理分享RTE(RealTimeEngagement)领域内「有话题的新闻」、「有态度的观点」、「有意思的数据」、「有思考的文章」、「有看点的会议」,但内容仅代表......
  • 【百度智能云】AIGC-文生图
    从地址https://console.bce.baidu.com/ai/#/ai/intelligentwriting/app/list创建应用,然后复制应用的APIKey和SecretKey到下文的API_KEY_AIGC和SECRET_KEY_AIGCimportjsonimportosimporttime#debugimporthttp.clientimportsslfromurllib.parseimport......
  • Sora文生视频模型深度剖析:全网独家指南,洞悉98%关键信息,纯干货
    Sora文生视频模型深度剖析:全网独家指南,洞悉98%关键信息,纯干货Sora是一个以视频生成为核心的多能力模型,具备以下能力:文/图生成视频视频生成视频1分钟超长高质量视频生成视频裂变多视角生成准工业级数字孪生游戏/科幻片等特效,物理引擎能力1.Sora与RunwayGen2、Pika等能......
  • 探索AI视频生成新纪元:文生视频Sora VS RunwayML、Pika及StableVideo——谁将引领未来
    探索AI视频生成新纪元:文生视频SoraVSRunwayML、Pika及StableVideo——谁将引领未来由于在AI生成视频的时长上成功突破到一分钟,再加上演示视频的高度逼真和高质量,Sora立刻引起了轰动。在Sora横空出世之前,Runway一直被视为AI生成视频的默认选择,尤其是自去年11月推出第二代模型以......
  • 开年王炸 | OpenAI首个文生视频模型Sora发布,这一次短视频、影视、游戏等行业或许将被
    前言北京时间2月16日,OpenAI突然发布首个文生视频模型Sora。这一模型可以根据用户输入的提示词直接生成长达60秒的高清视频,并且包含高度细致的场景、复杂的多角度镜头,以及生动的角色表情。平地一声雷,这次依然让人惊呼“又是王炸”,AI视频要变天了。Sora是什么Sora是OpenAI发布......
  • Sora、Pika文生视频模型对比
    OpenAI重磅发布文生视频模型Sora,Sora在视频时长与视觉效果等方面相较于Pika、Runway等主流文生视频工具有了极大幅度的提升。具体来看,Sora生成的视频具有超长时长、世界模型、多镜头切换的三大特性:1)超长时长Sora可生成长达一分钟的高清视频,而此前Pika、Runway等模型生......
  • Avalonia 越来越流行了,记录练手一个项目.就下载bing的图片吧
     只要有桌面需求那肯定掏出万年winform..偶然接触到了Avalonia把去年练手的项目整理了一下不知道大家练手都写什么...总的来说xaml习惯和wpf差不多.对于我这种经常写前端的后端来说.Avalonia支持css写法很省事. 技术栈Avalonia0.10.18NET7CommunityToolkit.Mvvm......
  • 告别 GPU 焦虑,玩转极致性价比的 CPU 文生图
    作者:壮怀、竹刚AIGC中的StableDiffusion文生图模型是开源流行的跨模态生成模型,用于生成给定文本对应的图像。但由于众所周知的原因,GPU资源出现了一卡难求的现状,如何通过云计算快速提升业务规模,降低文生图的计算成本,以及更好的保护自定义的扩展模型?针对文生图模型特性和规模......