Created
November 30, 2023 03:44
-
-
Save biranchi2018/fd2bcb0edbd760614a768872ae5d6b70 to your computer and use it in GitHub Desktop.
My Gradio Gists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Gradio : | |
========= | |
pip install gradio | |
============================================================= | |
https://www.gradio.app/playground | |
============================================================= | |
import gradio as gr | |
def greet(name): | |
return "Hello " + name + "!" | |
demo = gr.Interface(fn=greet, inputs="text", outputs="text") | |
if __name__ == "__main__": | |
demo.launch(show_api=False) | |
============================================================= | |
import gradio as gr | |
def greet(name): | |
return "Hello " + name + "!" | |
with gr.Blocks() as demo: | |
name = gr.Textbox(label="Name") | |
output = gr.Textbox(label="Output Box") | |
greet_btn = gr.Button("Greet") | |
greet_btn.click(fn=greet, inputs=name, outputs=output, api_name="greet") | |
if __name__ == "__main__": | |
demo.launch() | |
============================================================= | |
import random | |
import gradio as gr | |
def random_response(message, history): | |
return random.choice(["Yes", "No"]) | |
demo = gr.ChatInterface(random_response) | |
if __name__ == "__main__": | |
demo.launch() | |
============================================================= | |
import time | |
import gradio as gr | |
import requests | |
def slow_echo(message, history): | |
for i in range(len(message)): | |
time.sleep(0.05) | |
yield "You typed: " + message[: i+1] | |
demo = gr.ChatInterface(slow_echo).queue() | |
if __name__ == "__main__": | |
demo.launch() | |
============================================================= | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment