ThreeJS: How to import PositionalAudioHelper? [duplicate] - three.js

This question already has answers here:
Uncaught SyntaxError: Cannot use import statement outside a module
(2 answers)
Closed 2 years ago.
I'm trying to import the PositionalAudioHelper. The code is very basic:
// create the PositionalAudio object (passing in the listener)
import * as THREE from 'three';
var sound = new THREE.PositionalAudio( listener );
var helper = new THREE.PositionalAudioHelper(sound);
sound.add( helper );
The webpack error I get is:
"export 'PositionalAudioHelper' (imported as 'THREE') was not found in 'three'
I installed Three using yarn so it may not install the latest version that includes this commit: https://github.com/mrdoob/three.js/pull/15748
Any ideas on how to do this?

Since PositionalAudioHelper is located on the examples directoy, you have to import it like so:
import { PositionalAudioHelper } from 'three/examples/jsm/helpers/PositionalAudioHelper.js';
three.js R116

Related

python-telegram-bot for (v20.x) TypeError: bad operand type for unary ~: 'type'

I am trying to build a telegram bot, I have just reproduce the code:
from telegram.ext import MessageHandler
from telegram.ext import filters
from telegram.ext import Application
from telegram import Update
from telegram.ext import ContextTypes
from decouple import config
def testFunc (update: Update, context: ContextTypes.DEFAULT_TYPE):
print('Hi')
def main():
BOT_TOKEN = config('TELE_BOT_API_KEY_2')
application = Application.builder().token(BOT_TOKEN).build()
application.add_handler(MessageHandler(filters.Text & ~filters.Command, testFunc))
application.run_polling()
if __name__ == '__main__':
main()
The error this code shows is:
Bot\AsyncAdvanceBot\test3.py", line 16, in main
application.add_handler(MessageHandler(filters.Text & ~filters.Command, testFunc))
TypeError: bad operand type for unary ~: 'type'
I am using python-telegram-bot api v20.x
I know this might be a naive problem that I might be missing.
Thanks!
I tried changing the code to different format but it doesn't work.
I got it! It was as I said naive error. I was not thinking straight😅
I have seen the document even earlier and was only focusing on making filters.Command to filters.COMMAND, but forgot to change filters.Text to filters.TEXT.
just replaced
filters.Text & ~filters.Command
with
filters.TEXT & ~filters.COMMAND

Error when importing sklearn in pipeline component

When I run this simple pipeline (in GCP's Vertex AI Workbench) I get an error:
ModuleNotFoundError: No module named 'sklearn'
Here is my code:
from kfp.v2 import compiler
from kfp.v2.dsl import pipeline, component
from google.cloud import aiplatform
#component(
packages_to_install=["sklearn"],
base_image="python:3.9",
)
def test_sklearn():
import sklearn
#pipeline(
pipeline_root=PIPELINE_ROOT,
name="sklearn-pipeline",
)
def pipeline():
test_sklearn()
compiler.Compiler().compile(pipeline_func=pipeline, package_path="sklearn_pipeline.json")
job = aiplatform.PipelineJob(
display_name=PIPELINE_DISPLAY_NAME,
template_path="sklearn_pipeline.json",
pipeline_root=PIPELINE_ROOT,
location=REGION
)
job.run(service_account=SERVICE_ACCOUNT)
What do I do wrong? :)
It seems that the package name sklearn does not work after a version upgrade.You need to change the value of packages_to_install from "sklearn" to "scikit-learn" in the #component block.

Streamlit Unhashable TypeError when i use st.cache

when i use the st.cache decorator to cash hugging-face transformer model i get
Unhashable TypeError
this is the code
from transformers import pipeline
import streamlit as st
from io import StringIO
#st.cache(hash_funcs={StringIO: StringIO.getvalue})
def model() :
return pipeline("sentiment-analysis", model='akhooli/xlm-r-large-arabic-sent')
after searching in issues section in streamlit repo
i found that hashing argument is not required , just need to pass this argument
allow_output_mutation = True
This worked for me:
from transformers import pipeline
import tokenizers
import streamlit as st
import copy
#st.cache(hash_funcs={tokenizers.Tokenizer: lambda _: None, tokenizers.AddedToken: lambda _: None})
def get_model() :
return pipeline("sentiment-analysis", model='akhooli/xlm-r-large-arabic-sent')
input = st.text_input('Text')
bt = st.button("Get Sentiment Analysis")
if bt and input:
model = copy.deepcopy(get_model())
st.write(model(input))
Note 1:
calling the pipeline with input model(input) changes the model and we shouldn't change a cached value so we need to copy the model and run it on the copy.
Note 2:
First run will load the model using the get_model function next run will use the chace.
Note 3:
You can read more about Advanced caching in stremlit in thier documentation.
Output examples:

three.js import fails in Create React App

I have three.js installed in my Create React App project as:
"three": "^0.115.0",
When I try to import it in component by doing:
import * as THREE from "three"; then I get (abridged):
TypeError: attribute.onUploadCallback is not a function
createBuffer
node_modules/three/build/three.module.js:14471
14468 | gl.bindBuffer( bufferType, buffer );
14469 | gl.bufferData( bufferType, array, usage );
14470 |
> 14471 | attribute.onUploadCallback();
| ^ 14472 |
14473 | var type = 5126;
If I create a file such as:
import * as THREE from "three";
window.THREE = THREE;
export default window.THREE;
then I am able to successfully import from there.
I have no idea why I need to add it to window for it to work.
The error actually had to do with a related library that uses three.js called AMI.js.

where does cy variable coming from in cypress

I am have installed ESlint in out test project and it started to show me few errors that i need to resolve
one of the error is in cy.request('someURL');
The error is cy is undefined
so I have added a import statement on top of file like this
import { cy } from 'cypress';
After adding this statement none of the requests are going through I am getting this error when i try executing the tests.
Tests are executing perfects once i remove the import statement
where am i going wrong
cy is a global variable. Much like location. So really it is window.cy. You can add it to the globals in Eslint. Don't import cy from cypress.
{
"globals": {
"cy": true
}
}
/* global cy */
import above in your test file (cypress test file ex: cypress/integration/login.js

Resources