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

HF Callback not working with Urdu Text #841

Closed
kingabzpro opened this issue Mar 18, 2022 · 9 comments · Fixed by #1081
Closed

HF Callback not working with Urdu Text #841

kingabzpro opened this issue Mar 18, 2022 · 9 comments · Fixed by #1081
Assignees
Labels
bug Something isn't working
Milestone

Comments

@kingabzpro
Copy link

Describe the bug

The call back works fine with vision and chatbot but with ASR it's generating error and I cant seem to figure it out.

Reproduction

Link to app: https://huggingface.co/spaces/kingabzpro/Urdu-ASR-SOTA
Link to dataset: https://huggingface.co/datasets/kingabzpro/Urdu-ASR-flags/tree/main

Screenshot

Uploading image.png…

Logs

ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/home/user/.local/lib/python3.8/site-packages/uvicorn/protocols/http/h11_impl.py", line 366, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "/home/user/.local/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 75, in __call__
    return await self.app(scope, receive, send)
  File "/home/user/.local/lib/python3.8/site-packages/fastapi/applications.py", line 261, in __call__
    await super().__call__(scope, receive, send)
  File "/home/user/.local/lib/python3.8/site-packages/starlette/applications.py", line 112, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/user/.local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in __call__
    raise exc
  File "/home/user/.local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in __call__
    await self.app(scope, receive, _send)
  File "/home/user/.local/lib/python3.8/site-packages/starlette/middleware/cors.py", line 92, in __call__
    await self.simple_response(scope, receive, send, request_headers=headers)
  File "/home/user/.local/lib/python3.8/site-packages/starlette/middleware/cors.py", line 147, in simple_response
    await self.app(scope, receive, send)
  File "/home/user/.local/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in __call__
    raise exc
  File "/home/user/.local/lib/python3.8/site-packages/starlette/exceptions.py", line 71, in __call__
    await self.app(scope, receive, sender)
  File "/home/user/.local/lib/python3.8/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
    raise e
  File "/home/user/.local/lib/python3.8/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "/home/user/.local/lib/python3.8/site-packages/starlette/routing.py", line 656, in __call__
    await route.handle(scope, receive, send)
  File "/home/user/.local/lib/python3.8/site-packages/starlette/routing.py", line 259, in handle
    await self.app(scope, receive, send)
  File "/home/user/.local/lib/python3.8/site-packages/starlette/routing.py", line 61, in app
    response = await func(request)
  File "/home/user/.local/lib/python3.8/site-packages/fastapi/routing.py", line 227, in app
    raw_response = await run_endpoint_function(
  File "/home/user/.local/lib/python3.8/site-packages/fastapi/routing.py", line 160, in run_endpoint_function
    return await dependant.call(**values)
  File "/home/user/.local/lib/python3.8/site-packages/gradio/routes.py", line 283, in flag
    await run_in_threadpool(
  File "/home/user/.local/lib/python3.8/site-packages/starlette/concurrency.py", line 39, in run_in_threadpool
    return await anyio.to_thread.run_sync(func, *args)
  File "/home/user/.local/lib/python3.8/site-packages/anyio/to_thread.py", line 28, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(func, *args, cancellable=cancellable,
  File "/home/user/.local/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 818, in run_sync_in_worker_thread
    return await future
  File "/home/user/.local/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 754, in run
    result = context.run(func, *args)
  File "/home/user/.local/lib/python3.8/site-packages/gradio/flagging.py", line 381, in flag
    filepath = component.save_flagged(
  File "/home/user/.local/lib/python3.8/site-packages/gradio/inputs.py", line 1295, in save_flagged
    return self.save_flagged_file(
  File "/home/user/.local/lib/python3.8/site-packages/gradio/component.py", line 60, in save_flagged_file
    file = processing_utils.decode_base64_to_file(data, encryption_key)
  File "/home/user/.local/lib/python3.8/site-packages/gradio/processing_utils.py", line 187, in decode_base64_to_file
    data, extension = decode_base64_to_binary(encoding)
  File "/home/user/.local/lib/python3.8/site-packages/gradio/processing_utils.py", line 182, in decode_base64_to_binary
    data = encoding.split(",")[1]
IndexError: list index out of range

System Info

HF Spaces, Edge browser

Severity

annoyance

@kingabzpro kingabzpro added the bug Something isn't working label Mar 18, 2022
@aliabid94
Copy link
Collaborator

Taking a look.

@aliabid94
Copy link
Collaborator

@abidlabs actually can you take a look? It has to do with the HF callback

@abidlabs
Copy link
Member

abidlabs commented Mar 19, 2022 via email

@abidlabs
Copy link
Member

Hi @kingabzpro, I tried to reproduce this issue, but was unable to, Specifically, can you try the following code locally and tell me if you run into any errors? (It's just a minimal version of your code)

import gradio as gr

def asr(audio):
    return "hello"

HF_TOKEN = ""  # replace with your token
hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "Urdu-ASR-flags2")


################### Gradio Web APP ################################

title = "Urdu Automatic Speech Recognition"

description = """
<p>
<center>
This model is a fine-tuned version of facebook/wav2vec2-xls-r-300m on the common_voice dataset.
</center>
</p>
<center>
<img src="https://huggingface.co/spaces/kingabzpro/Urdu-ASR-SOTA/resolve/main/Images/cover.jpg" alt="logo" width="550"/>
</center>
"""

article = "<p style='text-align: center'><a href='https://dagshub.com/kingabzpro/Urdu-ASR-SOTA' target='_blank'>Source Code on DagsHub</a></p><p style='text-align: center'><a href='https://huggingface.co/blog/fine-tune-xlsr-wav2vec2' target='_blank'>Fine-tuning XLS-R for Multi-Lingual ASR with 🤗 Transformers</a></p></center></p>"

examples = [["Sample/sample1.mp3"], ["Sample/sample2.mp3"], ["Sample/sample3.mp3"]]


Input = gr.inputs.Audio(
    source="microphone",
    type="filepath",
    optional=True,
    label="Please Record Your Voice",
)
Output = gr.outputs.Textbox(label="Urdu Script")

iface = gr.Interface(
    asr,
    Input,
    Output,
    title=title,
    flagging_options=["incorrect", "worst", "ambiguous"],
    flagging_callback=hf_writer,
    description=description,
    article=article,
    examples=examples,
    theme="grass",
)

iface.launch()

@kingabzpro
Copy link
Author

@abidlabs, it worked locally. But my return is Urdu text. If you replace "hello world" with "آپ کیا کر ر" then you will see the error. I think it is also causing HFcallback error. Unicode decode. I tried to normalize text but still face and error.

UnicodeEncodeError: 'charmap' codec can't encode characters in position 134-135: character maps to <undefined>

@abidlabs
Copy link
Member

abidlabs commented Mar 20, 2022

Ahh I see. I'll take a look at resolving unicode issues

@abidlabs abidlabs changed the title HF Callback for ASR not working. HF Callback not working with Urdu Text Mar 20, 2022
@kingabzpro
Copy link
Author

kingabzpro commented Mar 21, 2022

@abidlabs I was able to normalize text, but apart from that, there is another but strange error. When you selected examples.
image

    filepath = component.save_flagged(
  File "/home/user/.local/lib/python3.8/site-packages/gradio/inputs.py", line 1295, in save_flagged
    return self.save_flagged_file(
  File "/home/user/.local/lib/python3.8/site-packages/gradio/component.py", line 60, in save_flagged_file
    file = processing_utils.decode_base64_to_file(data, encryption_key)
  File "/home/user/.local/lib/python3.8/site-packages/gradio/processing_utils.py", line 187, in decode_base64_to_file
    data, extension = decode_base64_to_binary(encoding)
  File "/home/user/.local/lib/python3.8/site-packages/gradio/processing_utils.py", line 182, in decode_base64_to_binary
    data = encoding.split(",")[1]

This error occurs when you select the examples and flag them.

Again it might be related to unicode. I don't know.

@abidlabs abidlabs added this to the 3.0 milestone Apr 19, 2022
@omerXfaruq
Copy link
Contributor

@abidlabs Assigning it to you since you are taking a look into it, if not feel free to remove it.

@abidlabs
Copy link
Member

Hi @kingabzpro this fixed now, and the fix will be out as part of Gradio 3.0. Thanks for creating the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants