Skip to content

Commit d6b1247

Browse files
aliabid94Ali AbidAli Abidpngwn
authored
Svelte migration (WIP) (gradio-app#448)
* first migration commit * style comment * first mvp working with calculator * ali components * carousel * more changes * changes * add examples * examples support * more changes * interpretation * interpretation * submission state * first migration commit * style comment * first mvp working with calculator * ali components * carousel * more changes * changes * add examples * examples support * more changes * interpretation * interpretation * submission state * base image cropper * add image editor * css tweaks * remove dead code * finalise sketch tools * add webcam snapshot source * tweak config * tweak config * tweak config * tweaks * reset egg files * lockfile v2 * image tweaks * record audio from mic * add audio input components * audio tweaks * editable table * more table tweaks * sort columns * add row/col to table * add output table * fix broken paths * fix svelte build destination * fix svelte build destination again * fix gitignore * fix css * add themes * add all themes * snake core classnames * actually fix themes this time * merge changes Co-authored-by: Ali Abid <[email protected]> Co-authored-by: Ali Abid <[email protected]> Co-authored-by: pngwn <[email protected]>
1 parent 7f23f9b commit d6b1247

File tree

181 files changed

+12835
-47748
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+12835
-47748
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ build/
1212

1313
# JS build
1414
gradio/templates/frontend/static
15+
gradio/templates/frontend/build
16+
gradio/templates/frontend/global.css
1517

1618
# Secrets
1719
.env

demo/kitchen_sink/run.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,11 @@ def fn(
8686
fn,
8787
inputs=[
8888
gr.inputs.Textbox(default="Lorem ipsum", label="Textbox"),
89-
gr.inputs.Textbox(lines=3, placeholder="Type here..", label="Textbox 2"),
89+
gr.inputs.Textbox(lines=3, placeholder="Type here..",
90+
label="Textbox 2"),
9091
gr.inputs.Number(label="Number", default=42),
91-
gr.inputs.Slider(minimum=10, maximum=20, default=15, label="Slider: 10 - 20"),
92+
gr.inputs.Slider(minimum=10, maximum=20, default=15,
93+
label="Slider: 10 - 20"),
9294
gr.inputs.Slider(maximum=20, step=0.04, label="Slider: step @ 0.04"),
9395
gr.inputs.Checkbox(label="Checkbox"),
9496
gr.inputs.CheckboxGroup(
@@ -97,14 +99,17 @@ def fn(
9799
gr.inputs.Radio(label="Radio", choices=CHOICES, default=CHOICES[2]),
98100
gr.inputs.Dropdown(label="Dropdown", choices=CHOICES),
99101
gr.inputs.Image(label="Image", optional=True),
100-
gr.inputs.Image(label="Image w/ Cropper", tool="select", optional=True),
102+
gr.inputs.Image(label="Image w/ Cropper",
103+
tool="select", optional=True),
101104
gr.inputs.Image(label="Sketchpad", source="canvas", optional=True),
102105
gr.inputs.Image(label="Webcam", source="webcam", optional=True),
103106
gr.inputs.Video(label="Video", optional=True),
104107
gr.inputs.Audio(label="Audio", optional=True),
105-
gr.inputs.Audio(label="Microphone", source="microphone", optional=True),
108+
gr.inputs.Audio(label="Microphone",
109+
source="microphone", optional=True),
106110
gr.inputs.File(label="File", optional=True),
107-
gr.inputs.Dataframe(label="Dataframe", headers=["Name", "Age", "Gender"]),
111+
gr.inputs.Dataframe(label="Dataframe", headers=[
112+
"Name", "Age", "Gender"]),
108113
gr.inputs.Timeseries(x="time", y=["price", "value"], optional=True),
109114
],
110115
outputs=[
@@ -113,15 +118,17 @@ def fn(
113118
gr.outputs.Audio(label="Audio"),
114119
gr.outputs.Image(label="Image"),
115120
gr.outputs.Video(label="Video"),
116-
gr.outputs.HighlightedText(label="HighlightedText"),
121+
gr.outputs.HighlightedText(label="HighlightedText", color_map={
122+
"punc": "pink", "test 0": "blue"}),
117123
gr.outputs.HighlightedText(label="HighlightedText", show_legend=True),
118124
gr.outputs.JSON(label="JSON"),
119125
gr.outputs.HTML(label="HTML"),
120126
gr.outputs.File(label="File"),
121127
gr.outputs.Dataframe(label="Dataframe"),
122128
gr.outputs.Dataframe(label="Numpy", type="numpy"),
123129
gr.outputs.Carousel("image", label="Carousel"),
124-
gr.outputs.Timeseries(x="time", y=["price", "value"], label="Timeseries"),
130+
gr.outputs.Timeseries(
131+
x="time", y=["price", "value"], label="Timeseries"),
125132
],
126133
examples=[
127134
[
@@ -147,7 +154,7 @@ def fn(
147154
]
148155
]
149156
* 3,
150-
theme="huggingface",
157+
theme="default",
151158
title="Kitchen Sink",
152159
description="Try out all the components!",
153160
article="Learn more about [Gradio](http://gradio.app)",

demo/zip_two_files/tmp.zip

120 KB
Binary file not shown.

frontend/.dockerignore

-23
This file was deleted.

frontend/.eslintignore

-1
This file was deleted.

frontend/.gitignore

+2-21
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,4 @@
1-
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
1+
/node_modules/
2+
/public/build/
23

3-
# dependencies
4-
/node_modules
5-
/.pnp
6-
.pnp.js
7-
8-
# testing
9-
/coverage
10-
11-
# production
12-
/build
13-
14-
# misc
154
.DS_Store
16-
.env.local
17-
.env.development.local
18-
.env.test.local
19-
.env.production.local
20-
21-
npm-debug.log*
22-
yarn-debug.log*
23-
yarn-error.log*

frontend/README.md

+101-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,109 @@
1-
# Gradio Frontend
1+
*Psst — looking for a more complete solution? Check out [SvelteKit](https://kit.svelte.dev), the official framework for building web applications of all sizes, with a beautiful development experience and flexible filesystem-based routing.*
22

3-
This directory contains a React App that renders the frontend of the gradio framework.
3+
*Looking for a shareable component template instead? You can [use SvelteKit for that as well](https://kit.svelte.dev/docs#packaging) or the older [sveltejs/component-template](https://github.com/sveltejs/component-template)*
44

5-
## Development Setup
5+
---
66

7-
To make changes to the gradio frontend, you will need to have the following installed
8-
- npm / node
9-
- python3
10-
- gradio
7+
# svelte app
118

12-
Once node is installed, make sure to run `npm install` in this directory to install the node packages.
9+
This is a project template for [Svelte](https://svelte.dev) apps. It lives at https://github.com/sveltejs/template.
1310

14-
Because this is only the frontend of the library, you must first launch a Gradio interface running on port 7860, which will be used as a backend. You can use any of the demo projects in the gradio/demo folder to serve this backend role, but make sure that the port is set to 7860. Then you launch the development frontend by running `npm run start`. Once this is run, the frontend development will launch on port 3000. It will connect with port 7860 to load the initial configuration and make API calls on submit.
11+
To create a new project based on this template using [degit](https://github.com/Rich-Harris/degit):
1512

16-
As a Create-React-App, any changes you make in the code will automatically reflect in the development frontend.
13+
```bash
14+
npx degit sveltejs/template svelte-app
15+
cd svelte-app
16+
```
1717

18-
## Committing Changes
18+
*Note that you will need to have [Node.js](https://nodejs.org) installed.*
1919

20-
In production, the frontend is compiled and stored in the gradio/gradio/frontend directory. (This readme is in gradio/frontend, a different directory outside the python package). To compile, run `npm run build`. At the end of the process, you should see the message "Compiled successfully" - there may be an warning or error thrown about not being able to find bundle.css which you can ignore. To include the compiled js into your local python version of gradio, run `python3 setup.py install` and then launch a gradio interface. Your changes should be visible on port 7860.
20+
21+
## Get started
22+
23+
Install the dependencies...
24+
25+
```bash
26+
cd svelte-app
27+
npm install
28+
```
29+
30+
...then start [Rollup](https://rollupjs.org):
31+
32+
```bash
33+
npm run dev
34+
```
35+
36+
Navigate to [localhost:5000](http://localhost:5000). You should see your app running. Edit a component file in `src`, save it, and reload the page to see your changes.
37+
38+
By default, the server will only respond to requests from localhost. To allow connections from other computers, edit the `sirv` commands in package.json to include the option `--host 0.0.0.0`.
39+
40+
If you're using [Visual Studio Code](https://code.visualstudio.com/) we recommend installing the official extension [Svelte for VS Code](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode). If you are using other editors you may need to install a plugin in order to get syntax highlighting and intellisense.
41+
42+
## Building and running in production mode
43+
44+
To create an optimised version of the app:
45+
46+
```bash
47+
npm run build
48+
```
49+
50+
You can run the newly built app with `npm run start`. This uses [sirv](https://github.com/lukeed/sirv), which is included in your package.json's `dependencies` so that the app will work when you deploy to platforms like [Heroku](https://heroku.com).
51+
52+
53+
## Single-page app mode
54+
55+
By default, sirv will only respond to requests that match files in `public`. This is to maximise compatibility with static fileservers, allowing you to deploy your app anywhere.
56+
57+
If you're building a single-page app (SPA) with multiple routes, sirv needs to be able to respond to requests for *any* path. You can make it so by editing the `"start"` command in package.json:
58+
59+
```js
60+
"start": "sirv public --single"
61+
```
62+
63+
## Using TypeScript
64+
65+
This template comes with a script to set up a TypeScript development environment, you can run it immediately after cloning the template with:
66+
67+
```bash
68+
node scripts/setupTypeScript.js
69+
```
70+
71+
Or remove the script via:
72+
73+
```bash
74+
rm scripts/setupTypeScript.js
75+
```
76+
77+
If you want to use `baseUrl` or `path` aliases within your `tsconfig`, you need to set up `@rollup/plugin-alias` to tell Rollup to resolve the aliases. For more info, see [this StackOverflow question](https://stackoverflow.com/questions/63427935/setup-tsconfig-path-in-svelte).
78+
79+
## Deploying to the web
80+
81+
### With [Vercel](https://vercel.com)
82+
83+
Install `vercel` if you haven't already:
84+
85+
```bash
86+
npm install -g vercel
87+
```
88+
89+
Then, from within your project folder:
90+
91+
```bash
92+
cd public
93+
vercel deploy --name my-project
94+
```
95+
96+
### With [surge](https://surge.sh/)
97+
98+
Install `surge` if you haven't already:
99+
100+
```bash
101+
npm install -g surge
102+
```
103+
104+
Then, from within your project folder:
105+
106+
```bash
107+
npm run build
108+
surge public my-project.surge.sh
109+
```

frontend/craco.config.js

-49
This file was deleted.

0 commit comments

Comments
 (0)