V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  timelessg  ›  全部回复第 4 页 / 共 38 页
回复总数  757
1  2  3  4  5  6  7  8  9  10 ... 38  
2025 年 3 月 30 日
回复了 iptv 创建的主题 服务器 想租用一台独立服务器使用
这个 title 触发关键词了:doge
2025 年 3 月 15 日
回复了 tool3d 创建的主题 程序员 google 的新模型,智能文字修图,效果实在是很炸裂。
# This is a sample Python script.
import base64

# Press ⌃R to execute it or replace it with your code.
# Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings.


import requests
import json
import mimetypes
import os

BASE_URL = "https://generativelanguage.googleapis.com"
GEMINI_API_KEY = ""
IMG_PATH_2 = ""
DISPLAY_NAME = "TEXT"

# 获取 MIME 类型和文件大小
MIME_TYPE, _ = mimetypes.guess_type(IMG_PATH_2)
NUM_BYTES = os.path.getsize(IMG_PATH_2)

# 发送初始 resumable 上传请求
data = {"file": {"display_name": DISPLAY_NAME}}
headers = {
"X-Goog-Upload-Protocol": "resumable",
"X-Goog-Upload-Command": "start",
"X-Goog-Upload-Header-Content-Length": str(NUM_BYTES),
"X-Goog-Upload-Header-Content-Type": MIME_TYPE,
"Content-Type": "application/json",
}

response = requests.post(
f"{BASE_URL}/upload/v1beta/files?key={GEMINI_API_KEY}",
headers=headers,
json=data
)

# 提取上传 URL
upload_url = response.headers.get("X-Goog-Upload-URL")
if not upload_url:
print("Failed to get upload URL.")
exit(1)

# 读取文件数据并上传
with open(IMG_PATH_2, "rb") as f:
file_data = f.read()

headers = {
"Content-Length": str(NUM_BYTES),
"X-Goog-Upload-Offset": "0",
"X-Goog-Upload-Command": "upload, finalize"
}

response = requests.post(upload_url, headers=headers, data=file_data)
file_info = response.json()
file_uri = file_info.get("file", {}).get("uri")

if not file_uri:
print("Failed to get file URI.")
exit(1)

print(f"file_uri={file_uri}")

# 生成内容请求
data = {
"contents": [{
"parts": [
{"text": "把全部人脸替换成猫头"},
{"file_data": {"mime_type": "image/jpeg", "file_uri": file_uri}}
]
}],
"generationConfig": {"response_modalities": ["Text", "Image"]}
}
headers = {"Content-Type": "application/json"}

response = requests.post(
f"{BASE_URL}/v1beta/models/gemini-2.0-flash-exp:streamGenerateContent?key={GEMINI_API_KEY}",
headers=headers,
json=data
)

response_json = response.json()
with open("response.json", "w", encoding="utf-8") as f:
json.dump(response_json, f, ensure_ascii=False, indent=4)

try:
for item in response_json: # 遍历列表
candidates = item.get("candidates", [])
for candidate in candidates:
content = candidate.get("content", {})
parts = content.get("parts", [])

for part in parts:
inline_data = part.get("inlineData")
if inline_data and "data" in inline_data:
base64_data = inline_data["data"]
mime_type = inline_data.get("mimeType", "image/png")

# 生成对应的文件扩展名
ext = "jpg" if "jpeg" in mime_type else "png"
output_file = f"output.{ext}"

# 解码 Base64 并保存为图片
image_data = base64.b64decode(base64_data)
with open(output_file, "wb") as img_file:
img_file.write(image_data)

print(f"图片已保存为 {output_file}")
break # 找到第一张就退出
else:
continue
break
else:
continue
break

except Exception as e:
print(f"处理 Base64 数据时出错: {e}")
2025 年 3 月 14 日
回复了 571002217222 创建的主题 生活 求推荐一款婴儿车,价格 1000-2000 左右的,谢谢!
cybex carbon
2025 年 3 月 6 日
回复了 darkce 创建的主题 程序员 字节的 Lynx 跨端框架开源了
缺的永远不是跨平台框架,缺的是生态,flutter ,rn 已经把生态做起来了,而像是 skip 之类据说可以用 swifui 写 Android 的框架没生态谁会用,除了 UI 两端还要写一堆 actual
2025 年 2 月 20 日
回复了 Chicagoake 创建的主题 Mac mini Mac mini 搭配外接硬盘求推荐
硬盘选无缓,盒子尽量选 jhl7440 主控,祥硕发热略大
2025 年 2 月 9 日
回复了 main1234 创建的主题 iDev Xcode 这个 IDE 好难用啊,你们都是用什么 IDE 开发 IOS
Xcode 确实🌶︎🐔,比起花里胡哨的 Android studio ,🍎这几年真是不思进取
2025 年 1 月 25 日
回复了 shonnliberty 创建的主题 分享发现 kiwi 作者弃坑了
应该是作者向 edge 合并了 extension 的支持代码,相当于交给 edge 维护了
2025 年 1 月 22 日
回复了 BeijingBaby 创建的主题 音乐 多端同步听音乐是个很困难的事
spotify
2025 年 1 月 17 日
回复了 ShioWSX 创建的主题 职场话题 求问-启明星辰算是中厂吗?外面认可度咋样?
挺好的,阮大神之前不就是这公司的
2025 年 1 月 16 日
回复了 Int100 创建的主题 程序员 Mac 外接硬盘该怎么选择? 求推荐
如果是当系统盘,建议雷电 4 而且是 jhl8440 主控的,发热相对小不容易掉盘,固态就相对无所谓了,反正主控最多能跑到 3000
2025 年 1 月 15 日
回复了 rrubick 创建的主题 Android 如何入门 Android 开发
别看 Android view 了,直接上 compose
2024 年 12 月 26 日
回复了 hao7Chen 创建的主题 日本 第一次日本自由行的个人心得
日本无现金支付还是可以的,下次店里碰到 paypay 的二维码可以用支付宝扫试试能不能付款
2024 年 12 月 19 日
回复了 OOOten 创建的主题 日本 去日本玩,没法打电话的情况下应该怎么预定餐馆呢?
google voice
2024 年 12 月 1 日
回复了 isbase 创建的主题 电影 豆瓣评分这么高的新电影:《好东西》是啥情况
爱情神话的导演啊,值得一看
2024 年 11 月 30 日
回复了 blackguester 创建的主题 Swift 问一个关于 CALayer 的资源释放问题
当然是都要做了,不然引用一直在
Android 可以直接上 compose 了
1  2  3  4  5  6  7  8  9  10 ... 38  
关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   2068 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 44ms · UTC 12:23 · PVG 20:23 · LAX 04:23 · JFK 07:23
♥ Do have faith in what you're doing.