SoniTranslate icon indicating copy to clipboard operation
SoniTranslate copied to clipboard

Api request

Open ankelkoss opened this issue 1 year ago • 3 comments

Hello everyone! Does anyone have a working API request method for uploading, translating and downloading videos? The thing is that JS or Python is not my native programming language, I had some difficulties with implementing this. Thanks in advance!

ankelkoss avatar Nov 07 '24 14:11 ankelkoss

I get an error in response to a request, what am I doing wrong?

python

from gradio_client import Client
from gradio_client import Client, handle_file

client = Client("http://127.0.0.1/")

video_file = handle_file('Welcome.mp4')

result = client.predict(
     data_type="SUBMIT VIDEO",
  
     api_name="/swap_visibility"
)
print(result)

result = client.predict(
    [video_file], 
    "Hello!!",
    "Hello!!",
    "hf -censorship-",
    True,
    "large-v3",
    32,
    "float16",
    "English (en)",
    "Russian (ru)",
    1,
    1,
    "ru_speaker_2-Male BARK",
    "True",
    "Adjusting volumes and mixing audio",
    1.9,
    False,
    0.25,
    1.8,
    "srt",
    False,
    False,
    "Hello!!",
    False,
    False,
    True,
    15,
    "pyannote_2.1",
    "google_translator_batch",
    "video (mp4)",
    False,
    False,
    3,
    False,
    True,
    "openvoice_v2",
    True,
    "sentence",
    "",
    False,
    False,
    True,
    False,
    1,
    True,
    #api_name="/batch_multilingual_media_conversion"
    fn_index=20
)

print(result)

powershell

Loaded as API: http://127.0.0.1/ ✔
({'visible': True, 'value': None, '__type__': 'update'}, {'visible': False, 'value': '', '__type__': 'update'}, {'visible': False, 'value': '', '__type__': 'update'})
Traceback (most recent call last):
  File "C:\Users\shytov\Desktop\SoniTranslate\SoniTranslate4.py", line 15, in <module>
    result = client.predict(
             ^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\gradio_client\client.py", line 476, in predict
    ).result()
      ^^^^^^^^
  File "C:\Python312\Lib\site-packages\gradio_client\client.py", line 1513, in result
    return super().result(timeout=timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\concurrent\futures\_base.py", line 456, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\concurrent\futures\_base.py", line 401, in __get_result
    raise self._exception
  File "C:\Python312\Lib\concurrent\futures\thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\gradio_client\client.py", line 1132, in _inner
    predictions = _predict(*data)
                  ^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\gradio_client\client.py", line 1249, in _predict
    raise AppError(
gradio_client.exceptions.AppError: The upstream Gradio app has raised an exception: gradio.data_classes.FileData() argument after ** must be a mapping, not bool

docker log

2024-11-08 12:32:58 Traceback (most recent call last):
2024-11-08 12:32:58   File "/usr/local/lib/python3.10/site-packages/gradio/queueing.py", line 528, in process_events
2024-11-08 12:32:58     response = await route_utils.call_process_api(
2024-11-08 12:32:58   File "/usr/local/lib/python3.10/site-packages/gradio/route_utils.py", line 270, in call_process_api
2024-11-08 12:32:58     output = await app.get_blocks().process_api(
2024-11-08 12:32:58   File "/usr/local/lib/python3.10/site-packages/gradio/blocks.py", line 1904, in process_api
2024-11-08 12:32:58     inputs = await self.preprocess_data(
2024-11-08 12:32:58   File "/usr/local/lib/python3.10/site-packages/gradio/blocks.py", line 1627, in preprocess_data
2024-11-08 12:32:58     inputs_cached = block.data_model(**inputs_cached)  # type: ignore
2024-11-08 12:32:58 TypeError: gradio.data_classes.FileData() argument after ** must be a mapping, not bool

ankelkoss avatar Nov 08 '24 10:11 ankelkoss

do you figure it out?

MiroslavReiss avatar Nov 26 '24 15:11 MiroslavReiss

Try include the port number in hostname, in client line: client = Client("http://127.0.0.1/") maybe: client = Client("http://127.0.0.1:7860/")

rickgds80 avatar Jan 24 '25 22:01 rickgds80