Use relative paths for static files / API; add environment variealbe GRADIO_THEME

This commit is contained in:
Ali Abid 2021-06-03 12:07:40 -07:00
parent d0d899b877
commit c7790eabd7
8 changed files with 13 additions and 10 deletions

View File

@ -24,6 +24,7 @@ module.exports = {
},
entry: './src/index',
output: {
publicPath: "",
path: path.resolve(__dirname, '../gradio/frontend'),
filename: "static/bundle.js",
chunkFilename: "static/js/[name].chunk.js",

View File

@ -22,7 +22,7 @@
"webpack": "^4.44.2"
},
"scripts": {
"start": "REACT_APP_BACKEND_URL='http://localhost:7860' craco start",
"start": "REACT_APP_BACKEND_URL='http://localhost:7860/' craco start",
"build": "REACT_APP_BACKEND_URL='' craco build",
"test": "craco test",
"eject": "react-scripts eject"

View File

@ -68,7 +68,7 @@ export class GradioInterface extends React.Component {
this.handleExampleChange = this.handleExampleChange.bind(this);
this.state = this.get_default_state();
this.state["examples_page"] = 0;
this.examples_dir = process.env.REACT_APP_BACKEND_URL + (this.props.examples_dir === null ? "/file" + this.props.examples_dir + (this.props.examples_dir.endswith("/") ? "" : "/") : "/file");
this.examples_dir = process.env.REACT_APP_BACKEND_URL + (this.props.examples_dir === null ? "file" + this.props.examples_dir + (this.props.examples_dir.endswith("/") ? "" : "/") : "file");
}
get_default_state() {
let state = {};

View File

@ -3,7 +3,7 @@ import ReactDOM from 'react-dom';
import GradioInterface from './gradio';
let fn = async (data, action) => {
const output = await fetch(process.env.REACT_APP_BACKEND_URL + "/api/" + action + "/", {
const output = await fetch(process.env.REACT_APP_BACKEND_URL + "api/" + action + "/", {
method: "POST",
body: JSON.stringify({ "data": data }),
headers: {
@ -15,7 +15,7 @@ let fn = async (data, action) => {
async function get_config() {
if (process.env.REACT_APP_BACKEND_URL) { // dev mode
let config = await fetch(process.env.REACT_APP_BACKEND_URL + "/config");
let config = await fetch(process.env.REACT_APP_BACKEND_URL + "config");
config = await config.json()
return config;
} else {

View File

@ -35,6 +35,8 @@ gradio/frontend/static/css/main.20be28ac.css
gradio/frontend/static/css/main.20be28ac.css.map
gradio/frontend/static/css/main.380e3222.css
gradio/frontend/static/css/main.380e3222.css.map
gradio/frontend/static/css/main.4aea80f8.css
gradio/frontend/static/css/main.4aea80f8.css.map
gradio/frontend/static/css/main.99922310.css
gradio/frontend/static/css/main.99922310.css.map
gradio/frontend/static/css/main.acb02c85.css

View File

@ -1,17 +1,17 @@
{
"files": {
"main.css": "/static/css/main.380e3222.css",
"main.css": "/static/css/main.4aea80f8.css",
"main.js": "/static/bundle.js",
"main.js.map": "/static/bundle.js.map",
"index.html": "/index.html",
"static/bundle.css.map": "/static/bundle.css.map",
"static/bundle.js.LICENSE.txt": "/static/bundle.js.LICENSE.txt",
"static/css/main.380e3222.css.map": "/static/css/main.380e3222.css.map",
"static/css/main.4aea80f8.css.map": "/static/css/main.4aea80f8.css.map",
"static/media/logo_loading.e93acd82.jpg": "/static/media/logo_loading.e93acd82.jpg"
},
"entrypoints": [
"static/bundle.css",
"static/css/main.380e3222.css",
"static/css/main.4aea80f8.css",
"static/bundle.js"
]
}

View File

@ -8,4 +8,4 @@
window.config = {{ config|tojson }};
} catch (e) {
window.config = {};
}</script><title>Gradio</title><link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet"><link href="/static/bundle.css" rel="stylesheet"><link href="/static/css/main.380e3222.css" rel="stylesheet"></head><body><div id="root"></div><script src="/static/bundle.js"></script></body></html>
}</script><title>Gradio</title><link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet"><link href="static/bundle.css" rel="stylesheet"><link href="static/css/main.4aea80f8.css" rel="stylesheet"></head><body><div id="root"></div><script src="static/bundle.js"></script></body></html>

View File

@ -66,7 +66,7 @@ class Interface:
def __init__(self, fn, inputs=None, outputs=None, verbose=False, examples=None,
examples_per_page=10, live=False,
layout="horizontal", show_input=True, show_output=True,
capture_session=False, interpretation=None, theme="default", repeat_outputs_per_model=True,
capture_session=False, interpretation=None, theme=None, repeat_outputs_per_model=True,
title=None, description=None, article=None, thumbnail=None,
css=None, server_port=None, server_name=networking.LOCALHOST_NAME, height=500, width=900,
allow_screenshot=True, allow_flagging=True, flagging_options=None, encrypt=False,
@ -155,7 +155,7 @@ class Interface:
article = markdown2.markdown(article)
self.article = article
self.thumbnail = thumbnail
self.theme = theme
self.theme = theme if theme is not None else os.getenv("GRADIO_THEME", "default")
self.height = height
self.width = width
if css is not None and os.path.exists(css):