Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Q&A] How to use nested categories #835

Closed
pawssx opened this issue Oct 15, 2023 · 13 comments · Fixed by #836
Closed

[Q&A] How to use nested categories #835

pawssx opened this issue Oct 15, 2023 · 13 comments · Fixed by #836
Labels
fixed BUG 已修复或问题已解决

Comments

@pawssx
Copy link

pawssx commented Oct 15, 2023

Brief description

Hi! i have problem while running nested prompt: "Please click on the largest animal." I can see they have .onyx models and they are in objects.yaml but i dont now how to run it propertly.I use demo_classify.py from examples. I would be grateful for any help.

Error

2023-10-15 18:39:56 | DEBUG - Types of challenges not yet scheduled - {'label': 'please click on the largest animal', 'prompt': 'Please click on the largest animal.'}
@QIN2DIM
Copy link
Owner

QIN2DIM commented Oct 15, 2023

upgrade to latest version v0.8.7 ++

pip install -U hcaptcha-challenger[playwright]

and install(upgrade=True) to refresh assets cache

@QIN2DIM QIN2DIM added the fixed BUG 已修复或问题已解决 label Oct 15, 2023
@pawssx
Copy link
Author

pawssx commented Oct 15, 2023

I tried version 0.8.7, 0.8.7-post1 and pip install -U hcaptcha-challenger[playwright] all with install(upgrade=True) but still im getting same error 2023-10-15 19:08:08 | DEBUG - Types of challenges not yet scheduled - {'label': 'please click on the largest animal', 'prompt': 'Please click on the largest animal.'}

@QIN2DIM
Copy link
Owner

QIN2DIM commented Oct 15, 2023

How do you use it 0.0

@QIN2DIM
Copy link
Owner

QIN2DIM commented Oct 15, 2023

fine, I didn't export this feat as an example. If you do not use it in the context of AgentT, you cannot activate trigger this feature.

'nested categories' needs to provide an' example image 'and a' challenge prompt 'to filter and sort models, and then select the best model to do the second processing of' challenge images'.

def _rank_models(self) -> ResNetControl | None:
nested_models = self.nested_categories.get(self._label, [])
if not nested_models:
return
rank_ladder = []
# {{< Rank ResNet Models >}}
for example_path in self._example_paths:
img_stream = example_path.read_bytes()
for model_name in nested_models:
net = self.modelhub.match_net(focus_name=model_name)
control = ResNetControl.from_pluggable_model(net)
result_, proba = control.execute(img_stream, proba=True)
if result_:
rank_ladder.append([control, model_name, proba])
if proba[0] > 0.87:
break
# {{< Catch-all Rules >}}
if rank_ladder:
alts = sorted(rank_ladder, key=lambda x: x[-1][0], reverse=True)
best_model, model_name = alts[0][0], alts[0][1]
logger.debug("rank model", resnet=model_name, prompt=self._prompt)
return best_model

if self.qr.request_type == "image_label_binary":
if self.nested_categories.get(self._label):
if model := self._rank_models():
await self._binary_challenge(frame_challenge, model)
else:
return self.status.CHALLENGE_BACKCALL
elif self.label_alias.get(self._label):
await self._binary_challenge(frame_challenge)
else:
return self.status.CHALLENGE_BACKCALL

@pawssx
Copy link
Author

pawssx commented Oct 15, 2023

So what would I have to change in demo_classify.py to make it work? I'm too stupid to understand how it works exactly. I would be very grateful for your help.

@QIN2DIM
Copy link
Owner

QIN2DIM commented Oct 15, 2023

@pawssx @vxrip So what I'm saying is, how do you use this program, I can just wrap a high-level interface.

@pawssx
Copy link
Author

pawssx commented Oct 16, 2023

Im currently using demo_classify.py: `
import os
from pathlib import Path

import hcaptcha_challenger as solver

solver.install(upgrade=True)

prompt = "diamond bracelet"

label_dir = Path(file).parent.joinpath("diamond_bracelet")

images = [label_dir.joinpath(fn).read_bytes() for fn in os.listdir(label_dir)]

def bytedance():
classifier = solver.BinaryClassifier()
if result := classifier.execute(prompt, images):
for i, name in enumerate(os.listdir(label_dir)):
print(f"{name} - {result[i]}")

if name == "main":
bytedance()
`

But if nested categories dont work on this code i can switch to anything but without selenium and as always i will be very grateful for help

@QIN2DIM
Copy link
Owner

QIN2DIM commented Oct 16, 2023

I mean, how did you import hcaptcha_challenger and use it in your project.

It's impossible to just run this example, right?😅

Since you'll be thinking about handling the largest animal challenge prompt, you should need a browser rendering challenge, so you can use the playwright version of the code. I guess

@pawssx
Copy link
Author

pawssx commented Oct 16, 2023

Im using hcaptcha challenger literally same as demo_classify code here:

import os, json
from pathlib import Path
import time
import hcaptcha_challenger as solver
solver.install(flush_yolo=True, upgrade=True)

def solvecapclas(prompt: str, path: str):
    cap_prompt = prompt
    label_dir = Path(__file__).parent.joinpath("solverdata", "classify", path)
    images = [label_dir.joinpath(fn).read_bytes() for fn in os.listdir(label_dir)]

    classifier = solver.BinaryClassifier()

  
    if result := classifier.execute(cap_prompt, images):

        answers1 = {
            name[:-5]: result[i]
            for i, name in enumerate(os.listdir(label_dir))
        }
        return json.dumps(answers1)

Im getting all the images from request. I want to notice that from that from that same request i can get example_question soo it would be possible to specify a .onyx model without selenium but im not too smart to do this

@QIN2DIM
Copy link
Owner

QIN2DIM commented Oct 16, 2023

emmmm......

This looks like it's just a change to the example code.

@pawssx
Copy link
Author

pawssx commented Oct 16, 2023

its literally 1:1 thats why im asking if its possible that you could help me or do a new example i was thinking about separate .onyx model that will match example images

@QIN2DIM
Copy link
Owner

QIN2DIM commented Oct 16, 2023

Your requirement is too simple, I changed some of the code of classifier, you only need to pass one more parameter.

see more:

https://github.com/QIN2DIM/hcaptcha-challenger/blob/main/examples/demo_rank_largest_animal.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed BUG 已修复或问题已解决
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
@QIN2DIM @pawssx and others