Spaces:
Sleeping
Sleeping
import gradio as gr | |
import random | |
glHTML = """ | |
<html> | |
<head> | |
<script type="module" crossorigin src="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.js"></script> | |
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.css" /> | |
</head> | |
<body> | |
<gradio-lite> | |
{0} | |
</gradio-lite> | |
</body> | |
</html> | |
""" | |
defaultCode = """ | |
import gradio as gr | |
def greet(name): | |
return "Hello, " + name + "!" | |
gr.Interface(greet, "textbox", "textbox").launch() | |
""" | |
def letterize(x): | |
names = [ | |
"Jake", | |
"John", | |
"Greg Heffley", | |
"Mark Zuckerberg", | |
"Ian", | |
"Scotland", | |
"Bill Gates", | |
"Lil Nas X", | |
"Micheal Kovach" | |
] | |
return f""" | |
Dear {random.choices(names)[0]}, | |
{x} | |
Sincerely, {random.choices(names)[0]} | |
""" | |
def flip_text(x): | |
return x[::-1] | |
def txtRouletteHandler(x, y): | |
rn = random.randrange(2) | |
print(rn) | |
if (rn == 1): | |
return letterize(x) | |
elif (rn == 2): | |
return flip_text(x) | |
else: | |
return flip_text(x) | |
def check_cc(n): | |
digits = [int(d) for d in str(n)] | |
for i in range(1, len(digits), 2): | |
digits[i] *= 2 | |
total = sum(digits) | |
return "Valid\n\nNOW DON'T GO POSTING THAT NUMBER." if total % 2 == 0 and len(digits) == 16 else "Invalid" | |
#left for if i find out how to use this | |
def genGrUI(code): | |
print(glHTML.format(code)) | |
return glHTML.format(code) | |
with gr.Blocks(title="Josiah's Gradio Playground") as playground: | |
gr.Markdown("# Josiah's Gradio Playground") | |
gr.Markdown("Playing around with Gradio. Note that tabs marked as ⚠️ should not be used for malicious purposes.") | |
with gr.Tab("Tabs within Tabs"): | |
with gr.Tab("1. first"): | |
gr.Markdown("you're on 1") | |
with gr.Tab("2. third"): | |
gr.Markdown("you're on second") | |
with gr.Tab("Text Roulette"): | |
gr.ChatInterface(fn=txtRouletteHandler, examples=["Hello from USA!", "How is your day?", "skcus teliot idibiks"]) | |
with gr.Tab("⚠️ CC Validator"): | |
gr.Markdown("# THIS WAS NOT MEANT FOR MALICIOUS PURPOSES!") | |
gr.Markdown("This is meant to be a fun tool to use.") | |
num = gr.Textbox(label="CC Number (DO NOT USE MALICIOUSLY)") | |
valid = gr.Textbox(label="Is valid (DO NOT USE MALICIOUSLY)") | |
with gr.Row(): | |
validate = gr.Button("Validate", variant="primary") | |
gr.ClearButton([num, valid]) | |
validate.click(fn=check_cc, inputs=num,outputs=valid) | |
with gr.Tab("Changelog"): | |
with gr.Accordion("11/26/2023"): | |
with gr.Accordion("latest"): | |
gr.Markdown("fixed names appearing as lists") | |
with gr.Accordion("other"): | |
gr.Markdown("Removed gradio in gradio") | |
gr.Markdown("Added gradio in gradio") | |
gr.Markdown("Added CC Validator") | |
playground.launch() |