Code Monkey home page Code Monkey logo

Comments (5)

Jason-cs18 avatar Jason-cs18 commented on June 15, 2024

@whitphx

from gradio.

whitphx avatar whitphx commented on June 15, 2024

Thank you for this post, but unfortunately it is not possible to access local files from Gradio-Lite apps running in the browser because the browser environment (precisely, the Python/Pyodide environment in the browser in which Gradio-Lite runs) is completely isolated from the host OS.

An alternative solution is:

  1. serve the file through a web server so users can access it via a URL, e.g. http://your-host/sample.mp3
  2. mount it onto the Python env on the browser by using the gradio-file tag as below:
<gradio-lite>
import gradio as gr

demo = gr.Interface(
  fn=lambda x: x,
  inputs=gr.Audio(value="sample.mp3"),
  outputs=gr.Audio()
)

demo.launch()

<gradio-file name="sample.mp3" url="http://your-host/sample.mp3" />

</gradio-lite>

from gradio.

Jason-cs18 avatar Jason-cs18 commented on June 15, 2024

Thank you for this post, but unfortunately it is not possible to access local files from Gradio-Lite apps running in the browser because the browser environment (precisely, the Python/Pyodide environment in the browser in which Gradio-Lite runs) is completely isolated from the host OS.

An alternative solution is:

  1. serve the file through a web server so users can access it via a URL, e.g. http://your-host/sample.mp3
  2. mount it onto the Python env on the browser by using the gradio-file tag as below:
<gradio-lite>
import gradio as gr

demo = gr.Interface(
  fn=lambda x: x,
  inputs=gr.Audio(value="sample.mp3"),
  outputs=gr.Audio()
)

demo.launch()

<gradio-file name="sample.mp3" url="http://your-host/sample.mp3" />

</gradio-lite>

Thanks for your reply. If I use requests to get a video (named example.mp4) from remote API, how to access it?

<gradio-lite>
    audio_response = requests.post("https://xxxx/app/audio", json=myobj)
    audio_path = f"sample_output.mp3"
    with open(audio_path, 'wb') as file:
        for chunk in audio_response.iter_content(chunk_size=1024):
            file.write(chunk)

    # how to access sample_output.mp3?
</gradio-lite>

from gradio.

whitphx avatar whitphx commented on June 15, 2024

In that case, your Gradio-Lite app should be able to access the locally saved file "sample_output.mp3" by simply opening it, e.g. open("sample_output.mp3") or gr.Audio(value="sample_output.mp3").

from gradio.

abidlabs avatar abidlabs commented on June 15, 2024

Thanks @whitphx and @Jason-cs18, I'll go ahead and close this.

from gradio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.