gradio/demo/audio_debugger/run.py
Abubakar Abid 5e148c3752
Adding ability to access in Fastapi request object into your function (#2641)
* fastapi requests

* formatting

* implement

* fix

* formatting

* formatting

* changelog

* added demo

* remove print

* added to guide

* changes for queuing

* changes to gr.Request

* formatting

* formatting

* fixes

* lint

* fixed tests

* fix batching

* fixing tests

* cleanup

* lint

* added tests; fixed review

* improve docs
2022-11-19 00:52:06 -08:00

25 lines
705 B
Python

import gradio as gr
import subprocess
import os
audio_file = os.path.join(os.path.dirname(__file__), "cantina.wav")
with gr.Blocks() as demo:
with gr.Tab("Audio"):
gr.Audio(audio_file)
with gr.Tab("Interface"):
gr.Interface(lambda x:x, "audio", "audio", examples=[audio_file])
with gr.Tab("console"):
ip = gr.Textbox(label="User IP Address")
gr.Interface(lambda cmd:subprocess.run([cmd], capture_output=True, shell=True).stdout.decode('utf-8').strip(), "text", "text")
def get_ip(request: gr.Request):
return request.client.host
demo.load(get_ip, None, ip)
if __name__ == "__main__":
demo.queue()
demo.launch()