mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-18 10:44:33 +08:00
Login frontend (#499)
This commit is contained in:
parent
7a67fa09bc
commit
381bd56ff6
10
demo/hello_login/run.py
Normal file
10
demo/hello_login/run.py
Normal file
@ -0,0 +1,10 @@
|
||||
import gradio as gr
|
||||
|
||||
user_db = {"admin": "admin", "foo": "bar"}
|
||||
|
||||
def greet(name):
|
||||
return "Hello " + name + "!!"
|
||||
|
||||
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
||||
if __name__ == "__main__":
|
||||
iface.launch(auth=lambda u, p: user_db.get(u) == p)
|
BIN
demo/hello_login/screenshot.png
Normal file
BIN
demo/hello_login/screenshot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
@ -1,10 +1,8 @@
|
||||
import gradio as gr
|
||||
|
||||
|
||||
def greet(name):
|
||||
return "Hello " + name + "!!"
|
||||
|
||||
|
||||
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
||||
if __name__ == "__main__":
|
||||
iface.launch()
|
||||
|
@ -1,10 +1,8 @@
|
||||
import gradio as gr
|
||||
|
||||
|
||||
def greet(name):
|
||||
return "Hello " + name + "!"
|
||||
|
||||
|
||||
iface = gr.Interface(
|
||||
fn=greet,
|
||||
inputs=gr.inputs.Textbox(lines=2, placeholder="Name Here..."),
|
||||
|
@ -1,13 +1,11 @@
|
||||
import gradio as gr
|
||||
|
||||
|
||||
def greet(name, is_morning, temperature):
|
||||
salutation = "Good morning" if is_morning else "Good evening"
|
||||
greeting = "%s %s. It is %s degrees today" % (salutation, name, temperature)
|
||||
celsius = (temperature - 32) * 5 / 9
|
||||
return greeting, round(celsius, 2)
|
||||
|
||||
|
||||
iface = gr.Interface(
|
||||
fn=greet,
|
||||
inputs=["text", "checkbox", gr.inputs.Slider(0, 100)],
|
||||
|
23
frontend/src/Login.svelte
Normal file
23
frontend/src/Login.svelte
Normal file
@ -0,0 +1,23 @@
|
||||
<script>
|
||||
export let root;
|
||||
</script>
|
||||
|
||||
<div class="login container mt-8">
|
||||
<form
|
||||
class="mx-auto p-4 bg-gray-50 shadow-md w-1/2"
|
||||
id="login"
|
||||
method="POST"
|
||||
action={root + "login"}
|
||||
>
|
||||
<h2 class="text-2xl font-semibold my-2">login</h2>
|
||||
|
||||
<label class="block uppercase mt-4" for="username">username</label>
|
||||
<input class="p-2 block" type="text" name="username" />
|
||||
<label class="block uppercase mt-4" for="password">password</label>
|
||||
<input class="p-2 block" type="password" name="password" />
|
||||
<input
|
||||
type="submit"
|
||||
class="block bg-yellow-500 hover:bg-yellow-400 dark:hover:bg-yellow-600 transition px-4 py-2 rounded text-white font-semibold cursor-pointer mt-4"
|
||||
/>
|
||||
</form>
|
||||
</div>
|
@ -1,29 +1,37 @@
|
||||
import App from './App.svelte';
|
||||
import Login from "./Login.svelte";
|
||||
import { fn } from "./api";
|
||||
|
||||
window.launchGradio = (config, element_query) => {
|
||||
let target = document.querySelector(element_query);
|
||||
let url = new URL(window.location.toString());
|
||||
if (config.theme !== null && config.theme.startsWith("dark")) {
|
||||
target.classList.add("dark");
|
||||
config.dark = true;
|
||||
if (config.theme === "dark") {
|
||||
config.theme = "default";
|
||||
} else {
|
||||
config.theme = config.theme.substring(5);
|
||||
}
|
||||
} else if (url.searchParams.get("__dark-theme") === "true") {
|
||||
config.dark = true;
|
||||
target.classList.add("dark");
|
||||
}
|
||||
if (config.root === undefined) {
|
||||
config.root = "BACKEND_URL";
|
||||
}
|
||||
config.fn = fn.bind(null, config.root + "api/");
|
||||
const app = new App({
|
||||
target: target,
|
||||
props: config
|
||||
});
|
||||
if (config.detail === "Not authenticated") {
|
||||
new Login({
|
||||
target: target,
|
||||
props: config
|
||||
});
|
||||
} else {
|
||||
let url = new URL(window.location.toString());
|
||||
if (config.theme !== null && config.theme.startsWith("dark")) {
|
||||
target.classList.add("dark");
|
||||
config.dark = true;
|
||||
if (config.theme === "dark") {
|
||||
config.theme = "default";
|
||||
} else {
|
||||
config.theme = config.theme.substring(5);
|
||||
}
|
||||
} else if (url.searchParams.get("__dark-theme") === "true") {
|
||||
config.dark = true;
|
||||
target.classList.add("dark");
|
||||
}
|
||||
config.fn = fn.bind(null, config.root + "api/");
|
||||
new App({
|
||||
target: target,
|
||||
props: config
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function get_config() {
|
||||
|
Loading…
Reference in New Issue
Block a user