柚子快報激活碼778899分享:文心一言情感關懷之旅
柚子快報激活碼778899分享:文心一言情感關懷之旅
【AGIFoundathon】文心一言情感關懷之旅,讓我們一起來體驗吧!
上傳一張照片,用ernie-bot生成專屬于你的小故事!
此項目主要使用clip_interrogator獲取圖片的關鍵信息,然后將此關鍵信息用百度翻譯API翻譯成中文后,使用封裝了??API的Ernie Bot SDK(ernie-bot)生成故事,最后使用百度智能云長文本合成語音API。
1 快速開始
1.1 環(huán)境安裝
%cd ~/launch
!pip install -r requirements.txt --user
1.2 數(shù)據(jù)下載
!wget https://paddlenlp.bj.bcebos.com/models/community/Salesforce/blip-image-captioning-large/data.zip
# 將data文件解壓至clip_interrogator目錄下
!unzip -d /home/aistudio/launch/clip_interrogator data.zip
2 技術路徑
2.1 Clip_Interrogator
Clip Interrogator是一個提示工程工具,結合了OpenAI的CLIP和Salesforce的BLIP,用于優(yōu)化文本提示。它可以根據(jù)給定的圖像和文本生成提示,以幫助用戶更好地理解和編輯圖像。Clip Interrogator還提供了一些選項,如更改提示、調(diào)整強度等,使用戶能夠更好地控制生成的結果。此外,Clip Interrogator還支持多種語言,包括中文。要使用Clip Interrogator,用戶需要先安裝Python和必要的庫,并按照說明進行操作。
from PIL import Image
from clip_interrogator import Config, Interrogator
image_path = '/home/aistudio/launch/images/test02.jpg'
image = Image.open(image_path).convert('RGB')
ci = Interrogator(Config(clip_pretrained_model_name_or_path="openai/clip-vit-large-patch14"))
print(ci.interrogate_fast(image))
a girl is taking a selfie in a mirror, ulzzang, korean woman, korean girl, beautiful south korean woman, popular korean makeup, short flat hourglass slim figure, female actress from korea, korean face features, streaming on twitch, feminine slim figure, beautiful young korean woman, elegant high quality, photo of slim girl, girl silver ponytail hair
2.2 百度翻譯API
要使用百度翻譯API,您需要先在百度翻譯官網(wǎng)上注冊并獲取API密鑰。以下是使用百度翻譯API的步驟:
在百度翻譯官網(wǎng)上注冊并登錄。
在左側(cè)導航欄中選擇“API管理”。
點擊“前往API平臺”按鈕。
在API平臺頁面上,選擇“翻譯API”。
點擊“獲取密鑰”按鈕。
在彈出的對話框中,輸入相關信息并點擊“確定”。
等待一段時間,您的API密鑰將發(fā)送到您的注冊郵箱。
在郵箱中找到API密鑰并復制。
在您的應用程序中使用API密鑰,調(diào)用百度翻譯API進行翻譯操作。
請注意,在使用API之前,您需要了解API的使用規(guī)則和限制,以避免濫用和違反相關法規(guī)。此外,您還需要根據(jù)API文檔中的說明,編寫相應的代碼來調(diào)用API。
2.2.1 翻譯函數(shù)
import requests
import random
import json
from hashlib import md5
# 可以更換為你自己的appid/appkey.
appid = '20230805001770257'
appkey = '10MxfKpV0a5qT9s6fXt1'
# 如果需要更多語言的互譯,請閱讀以下地址 `https://api.fanyi.baidu.com/doc/21, 獲取更多信息。`
from_lang = 'en'
to_lang = 'zh'
endpoint = 'http://api.fanyi.baidu.com'
path = '/api/trans/vip/translate'
url = endpoint + path
# Generate salt and sign
def make_md5(s, encoding='utf-8'):
return md5(s.encode(encoding)).hexdigest()
def translate(query)
柚子快報激活碼778899分享:文心一言情感關懷之旅
好文鏈接
本文內(nèi)容根據(jù)網(wǎng)絡資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點和立場。
轉(zhuǎn)載請注明,如有侵權,聯(lián)系刪除。