Skip to content

Instantly share code, notes, and snippets.

@biranchi2018
Created November 30, 2023 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save biranchi2018/fd2bcb0edbd760614a768872ae5d6b70 to your computer and use it in GitHub Desktop.
Save biranchi2018/fd2bcb0edbd760614a768872ae5d6b70 to your computer and use it in GitHub Desktop.
My Gradio Gists
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