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

compute_language_confidence_values_in_parallel not working in Python code #237

Open
EmilioMoreno opened this issue Sep 10, 2024 · 0 comments

Comments

@EmilioMoreno
Copy link

EmilioMoreno commented Sep 10, 2024

Version 2.0.2, installed via pip3 install lingua-language-detector
When using compute_language_confidence_values_in_parallel I got the following error:

Error: argument 'texts': Can't extract 'str' to 'Vec'

The python code works flawlessly with compute_language_confidence_values. Its been tested in linux with python 3.9.16 and macOS with python 3.9.19

code is quite simple:

from lingua import Language, LanguageDetectorBuilder

detector = LanguageDetectorBuilder.from_all_languages().with_preloaded_language_models().build()

@app.route('/lang_detect', methods=['POST'])
def lang_detect():
    data = request.data.decode('utf-8')  
    if data:
        confidence_values = detector.compute_language_confidence_values_in_parallel(data)
        top_confidences = sorted(confidence_values, key=lambda x: x.value, reverse=True)[:7]
        for confidence in top_confidences:
            print(f"{confidence.language.name}: {confidence.value:.2f}")
        confidence_dict = [
            {
                "language": confidence.language.name.lower(), 
                "value": round(confidence.value, 2)
            } 
            for confidence in top_confidences
        ]
        confidence_json = json.dumps(confidence_dict, indent=4)
        response = confidence_json
        return response, 200
    else:
        return jsonify({"error": "No data provided"}), 400
@pemistahl pemistahl changed the title compute_language_confidence_values_in_parallel not working: Error: argument 'texts': Can't extract str to Vec compute_language_confidence_values_in_parallel not working in Python code Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant