Comments (5)
from gradio.
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:
- serve the file through a web server so users can access it via a URL, e.g.
http://your-host/sample.mp3
- 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.
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:
- serve the file through a web server so users can access it via a URL, e.g.
http://your-host/sample.mp3
- 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.
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.
Thanks @whitphx and @Jason-cs18, I'll go ahead and close this.
from gradio.
Related Issues (20)
- How to use tool="sketch" in gradio 4.x? HOT 4
- Running `gradio cc dev --host x.x.x.x` on a remote machine does not work.
- Incorrect monitoring URL when using the root_path parameter
- Error when using js for event listeners HOT 1
- Audio component waveform slow rendering HOT 1
- [Gradio Client] cannot pass keyword arguments HOT 5
- ChatBot API documentation does not use keyword argument syntyax HOT 3
- 'use via API' page should (could?) use live values HOT 1
- `@gradio/client` iterator doesn't fully finish (i think)
- Cancelled generators do only get closed after gradio exits. HOT 3
- Use cookies to persist monitoring URL token
- Data event return empty data object in JS client HOT 1
- Redirect to the specified URL HOT 1
- nude girl
- Add 'enable_monitoring' to `gr.mount_gradio_app()`
- How to get uploaded image and if user draws a mask get it as a gray mask from ImageEditor HOT 2
- client <-> server function id mismatch when rendering within sub-blocks HOT 2
- Fails to send gr.Examples into gr.ImageEditor
- Cannot scroll the chatbot when an event listener where it is the output is called HOT 1
- No more "download the image" button
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gradio.