我使用的是苹果Mac M1:
OS: MacOS Monterey
Python 3.9.13
Run Code Online (Sandbox Code Playgroud)
我想使用实现语义搜索SentenceTransformer。
这是我的代码:
from sentence_transformers import SentenceTransformer
import faiss
from pprint import pprint
import time
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
def load_index():
index = faiss.read_index("movie_plot.index")
return index
def fetch_movie_info(dataframe_idx):
info = df.iloc[dataframe_idx]
meta_dict = dict()
meta_dict['Title'] = info['Title']
meta_dict['Plot'] = info['Plot'][:500]
return meta_dict
def search(query, top_k, index, model):
print("starting search!")
t=time.time()
query_vector = model.encode([query])
top_k = index.search(query_vector, top_k)
print('>>>> Results in …Run Code Online (Sandbox Code Playgroud) 我正在尝试将图像保存到 indexeddb,然后在 React 应用程序中获取并显示它们。我的方法是将图像转换为 blob 并将 blob url 保存到 indexeddb,然后在需要显示时获取 blob url 并将图像 url 设置为 .src。
我是如何创建 blob 的
fetch(imgurl, {
mode: 'no-cors',
method: "get",
headers: {
"Content-Type": "application/json"
}
})
.then(response => response.blob())
.then(async images => {
var blob_url = URL.createObjectURL(images)
var blobA = blob_url.replace("blob:","")
var blobB = blobA.replace('"','')Run Code Online (Sandbox Code Playgroud)
这是 bloburl blob:http://localhost:3000/d7a55f39-b496-476b-8c3c-857874bd107c
然后,我删除 blob: 并将此网址保存在 indexeddb 中,以便在需要时获取 http://localhost:3000/d7a55f39-b496-476b-8c3c-857874bd107c
这是我需要使用 blob 图像的地方
import React from "react";
import { Row, Col, Container, Image } from 'react-bootstrap';
function Item({ item }) { …Run Code Online (Sandbox Code Playgroud)我有数千个 pdf 文件需要从中提取数据。这是一个pdf示例。我想从示例 pdf 中提取此信息。
我对 Nodejs、Python 或任何其他有效的方法持开放态度。我对python和nodejs了解甚少。我尝试使用 python 与此代码
import PyPDF2
try:
pdfFileObj = open('test.pdf', 'rb')
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
pageNumber = pdfReader.numPages
page = pdfReader.getPage(0)
print(pageNumber)
pagecontent = page.extractText()
print(pagecontent)
except Exception as e:
print(e)Run Code Online (Sandbox Code Playgroud)
但我陷入了如何查找采购历史记录的困境。从 pdf 中提取采购历史记录的最佳方法是什么?
我正在尝试在 Mac M1 上运行此阅读文本 。当我尝试运行这段代码时
python3 make_keras_charnet_model.py
Run Code Online (Sandbox Code Playgroud)
我收到错误
Using Theano backend.
Traceback (most recent call last):
File "/Users/name/miniforge3/envs/ocr_env/lib/python3.8/site-packages/theano/gof/cutils.py", line 305, in <module>
from cutils_ext.cutils_ext import * # noqa
ImportError: dlopen(/Users/name/.theano/compiledir_macOS-12.0-arm64-i386-64bit-i386-3.8.6-64/cutils_ext/cutils_ext.so, 0x0002): tried: '/Users/name/.theano/compiledir_macOS-12.0-arm64-i386-64bit-i386-3.8.6-64/cutils_ext/cutils_ext.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/local/lib/cutils_ext.so' (no such file), '/usr/lib/cutils_ext.so' (no such file)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/name/miniforge3/envs/ocr_env/lib/python3.8/site-packages/theano/gof/cutils.py", line 316, in <module>
from cutils_ext.cutils_ext import * # noqa
ImportError: …Run Code Online (Sandbox Code Playgroud) 我之前使用下面的代码来抓取单词搜索的搜索结果,例如https://www.walmart.com/上的书籍。他们当前已更改请求和响应参数,并且此代码不会再次得到任何响应。
params = {
'query': 'book',
'cat_id': 0,
'ps': 24,
'offset': 0,
'prg': 'desktop',
'stores': re.search(r'store/(\d+)', url).group(1)
}
try:
data1 = requests.get(api_url, params=params).json()
except Exception as e:
print("Sleeping for 10 seconds", e)
time.sleep(10)
try:
data1 = requests.get(api_url, params=params).json()
except Exception as e:
print("sleeping for 60 seconds", e)
time.sleep(60)
try:
data1 = requests.get(api_url, params=params).json()
except Exception as e:
print("sleeping for 360 seconds")
time.sleep(360)
data1 = requests.get(api_url, params=params).json()
Run Code Online (Sandbox Code Playgroud)
我想获取产品页面的 json 响应,例如此 url 中的产品
https://www.walmart.com/ip/SKIPPY-Natural-Creamy-Peanut-Butter-Spread-15-oz/37447671
Run Code Online (Sandbox Code Playgroud)
我如何使用当前参数重写代码以获得 json 响应?
我想让用户保持登录状态,并且每次打开应用程序时都不需要显示登录表单。我正在使用 MongoDB Realm 进行数据库和身份验证。现在登录工作正常,但每次打开应用程序时都需要登录。
这是我的登录代码
@objc func signUp() {
setLoading(true);
app.usernamePasswordProviderClient().registerEmail(username!, password: password!, completion: {[weak self](error) in
// Completion handlers are not necessarily called on the UI thread.
// This call to DispatchQueue.main.sync ensures that any changes to the UI,
// namely disabling the loading indicator and navigating to the next page,
// are handled on the UI thread:
DispatchQueue.main.sync {
self!.setLoading(false);
guard error == nil else {
print("Signup failed: \(error!)")
self!.errorLabel.text = "Signup failed: \(error!.localizedDescription)"
return
}
print("Signup successful!") …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个 python 字典,其中包含一个键集合,每个键有多个值。我希望能够向字典中的现有键添加值。我已经审查了有关此问题的多个线程,但我还没有找到直接适用的线程。
这是密钥的格式
{ "key1":{"value1-1 Attr": "value1-1","value1-2 Attr": "value1-2","value1-3 Attr": "value1-3", "Key2":{"value2-1 Attr": "value2-1","value2-2 Attr": "value2-2","value2-3 Attr": "value2-3",{} }
Run Code Online (Sandbox Code Playgroud)
我希望能够添加新密钥并增加现有密钥的值,因此我尝试了以下 Python 代码:
message1 = {"value1-4 Attr": "value1-4","value1-5 Attr": "value1-6","value1-7 Attr": "value1-7"}
if key in dictionary:
dictionary[key].append(message1)
else:
dictionary[key] =message1
Run Code Online (Sandbox Code Playgroud)
计划稍后将字典写入 json 文件。问题是我不断收到此错误,我不知道如何解决:
“dict”对象没有属性“append”
我该如何修复该错误以及向现有密钥添加新值的最佳方法是什么?
我正在尝试在我的 Node.js 中使用 google 文本转语音和其他翻译服务,但是当我连接到 google api 时,我收到此错误消息
“您的应用程序已使用来自 Google Cloud SDK 或 Google Cloud Shell 的最终用户凭据进行身份验证,但 texttospeech.googleapis.com 不支持这些凭据。我们建议在 gcloud 中配置 billing/quota_project 设置,或通过 auth/impersonate_service_account 使用服务帐户设置。有关服务帐户以及如何在应用程序中使用它们的更多信息,请参阅https://cloud.google.com/docs/authentication/。如果您使用curl或类似工具遇到此错误,您可能需要指定“X-Goog-User-Project”HTTP 标头用于配额和计费目的。有关“X-Goog-User-Project”标头的更多信息,请查看https://cloud.google.com/apis/docs/system-参数。” ,元数据:元数据{internalRepr:Map(2){'google.rpc.errorinfo-bin'=> [Array],'grpc-status-details-bin'=> [Array]},选项:{}},注意: '重试方法中发生异常,未归类为瞬态'}
因此,经过多次研究,我尝试验证我是否正在使用我的服务帐户凭据进行身份验证。我运行了这个命令
gcloud auth activate-service-account --key-file=./auth/service_acct_key.json
Run Code Online (Sandbox Code Playgroud)
它表明了这一点
已激活的服务帐户凭据:[firebase-adminsdk-uwecx@xxxxx.iam.gserviceaccount.com]
但是当再次运行服务器时
node server.js
Run Code Online (Sandbox Code Playgroud)
我仍然收到错误
是什么导致了此错误以及如何正确进行身份验证?
google-api node.js google-text-to-speech service-accounts google-cloud-platform
我正在创建一个购物车,用户可以在其中将商品添加到购物车。用户单击 addtocart 按钮后,我想将产品 ID、名称、价格和数量保存到本地存储,然后在购物车页面上检索它们。所以我试过这个
var cart = new Array;
if (cart != []) {
cart = JSON.parse(localStorage["cart"]);
}
$('#addtocart').on('click', function(e) {
var qty = document.getElementById("p-qty").value;
var li = $(this).parent();
var product = {};
product.id = productid;
product.name = document.getElementById("nomenclature").innerHTML;
product.price = document.getElementById("productprice").innerHTML;
product.quantity = qty;
addToCart(product);
});
function addToCart(product) {
// Retrieve the cart object from local storage
if (localStorage) {
var cart = JSON.parse(localStorage['cart']);
cart.push(product);
localStorage.setItem('cart', JSON.stringify(cart));
}
// window.location = "html/cart.html"
}
Run Code Online (Sandbox Code Playgroud)
但我不断收到此错误
未捕获的类型错误:cart.push 不是函数
我做错了什么,我该如何解决?
python ×5
javascript ×2
node.js ×2
apple-m1 ×1
arrays ×1
blob ×1
dictionary ×1
google-api ×1
graphql ×1
jquery ×1
mongodb ×1
pdf ×1
pdf-scraping ×1
reactjs ×1
realm ×1
swift ×1
swiftui ×1
web-scraping ×1