From d3a680697ac2d1fb81722679cef7e55a17e09ee6 Mon Sep 17 00:00:00 2001 From: aliabid94 Date: Tue, 15 Feb 2022 16:32:42 -0800 Subject: [PATCH 1/6] black fix (#628) Co-authored-by: Ali Abid --- gradio/interface.py | 2 +- test/test_flagging.py | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/gradio/interface.py b/gradio/interface.py index fe1c7534e2..fafcc1076b 100644 --- a/gradio/interface.py +++ b/gradio/interface.py @@ -684,7 +684,7 @@ class Interface: if self.enable_queue is None: self.enable_queue = enable_queue - if self.allow_flagging != "never": + if self.allow_flagging != "never": self.flagging_callback.setup(self.flagging_dir) config = self.get_config_file() diff --git a/test/test_flagging.py b/test/test_flagging.py index 4a42e8afc8..3837907f94 100644 --- a/test/test_flagging.py +++ b/test/test_flagging.py @@ -71,23 +71,21 @@ class TestDisableFlagging(unittest.TestCase): def test_flagging_no_permission_error_with_flagging_disabled(self): with tempfile.TemporaryDirectory() as tmpdirname: os.chmod(tmpdirname, 0o444) # Make directory read-only - nonwritable_path = os.path.join( - tmpdirname, 'flagging_dir') - + nonwritable_path = os.path.join(tmpdirname, "flagging_dir") + io = gr.Interface( lambda x: x, "text", "text", allow_flagging="never", - flagging_dir=nonwritable_path + flagging_dir=nonwritable_path, ) try: io.launch(prevent_thread_lock=True) except PermissionError: self.fail("launch() raised a PermissionError unexpectedly") - + io.close() - if __name__ == "__main__": From 1b69d1cb9576bf8650517310801537728e736953 Mon Sep 17 00:00:00 2001 From: Pierre Fernandez Date: Wed, 16 Feb 2022 01:37:15 +0100 Subject: [PATCH 2/6] added french --- ui/packages/app/public/lang/fr.json | 19 +++++++++++++++++++ ui/packages/app/src/i18n.js | 2 ++ 2 files changed, 21 insertions(+) create mode 100644 ui/packages/app/public/lang/fr.json diff --git a/ui/packages/app/public/lang/fr.json b/ui/packages/app/public/lang/fr.json new file mode 100644 index 0000000000..372c75c52e --- /dev/null +++ b/ui/packages/app/public/lang/fr.json @@ -0,0 +1,19 @@ +{ + "interface": { + "submit": "Soumettre", + "clear": "Nettoyer", + "interpret": "Interpréter", + "flag": "Signaler", + "examples": "Exemples", + "drop_image": "Déposer l'Image Ici", + "drop_video": "Déposer la Vidéo Ici", + "drop_audio": "Déposer l'Audio Ici", + "drop_file": "Déposer le Fichier Ici", + "drop_csv": "Déposer le CSV Ici", + "or": "ou", + "click_to_upload": "Cliquer pour Télécharger", + "view_api": "Voir l'API", + "built_with_Gradio": "Conçu avec Gradio" + } + } + \ No newline at end of file diff --git a/ui/packages/app/src/i18n.js b/ui/packages/app/src/i18n.js index 1f5f26aa15..39b943106d 100644 --- a/ui/packages/app/src/i18n.js +++ b/ui/packages/app/src/i18n.js @@ -1,10 +1,12 @@ import { addMessages, init, getLocaleFromNavigator } from "svelte-i18n"; import en from "../public/lang/en.json"; import es from "../public/lang/es.json"; +import fr from "../public/lang/fr.json"; import ur from "../public/lang/ur.json"; addMessages("en", en); addMessages("es", es); +addMessages("fr", fr); addMessages("ur", ur); export function setupi18n() { From df30b538cde3785b713f396a9a292da0423499cf Mon Sep 17 00:00:00 2001 From: wilile26811249 Date: Wed, 16 Feb 2022 15:30:29 +0800 Subject: [PATCH 3/6] Added chinese lang --- ui/packages/app/public/lang/zh_TW.json | 18 ++++++++++++++++++ ui/packages/app/src/i18n.js | 2 ++ 2 files changed, 20 insertions(+) create mode 100644 ui/packages/app/public/lang/zh_TW.json diff --git a/ui/packages/app/public/lang/zh_TW.json b/ui/packages/app/public/lang/zh_TW.json new file mode 100644 index 0000000000..b6af49d578 --- /dev/null +++ b/ui/packages/app/public/lang/zh_TW.json @@ -0,0 +1,18 @@ +{ + "interface": { + "submit": "提交", + "clear": "清除", + "interpret": "解釋", + "flag": "Flag", + "examples": "範例", + "drop_image": "刪除圖片", + "drop_video": "刪除影片", + "drop_audio": "刪除音頻", + "drop_file": "刪除檔案", + "drop_csv": "刪除CSV", + "or": "或", + "click_to_upload": "點擊上傳", + "view_api": "查看API", + "built_with_Gradio": "使用Gradio構建" + } +} \ No newline at end of file diff --git a/ui/packages/app/src/i18n.js b/ui/packages/app/src/i18n.js index 1f5f26aa15..6495f6816b 100644 --- a/ui/packages/app/src/i18n.js +++ b/ui/packages/app/src/i18n.js @@ -2,10 +2,12 @@ import { addMessages, init, getLocaleFromNavigator } from "svelte-i18n"; import en from "../public/lang/en.json"; import es from "../public/lang/es.json"; import ur from "../public/lang/ur.json"; +import zh_TW from "../public/lang/zh_TW.json"; addMessages("en", en); addMessages("es", es); addMessages("ur", ur); +addMessages("zh_TW", zh_TW); export function setupi18n() { init({ From 6fdc76c31bbc3656121657c55744a827269de542 Mon Sep 17 00:00:00 2001 From: pngwn Date: Wed, 16 Feb 2022 09:57:04 +0000 Subject: [PATCH 4/6] Dataframe fixes (#607) * allow deletion of cells with backspace and delete * respect default data * remove logs --- .../input/DataFrame/DataFrame.svelte | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/ui/packages/app/src/components/input/DataFrame/DataFrame.svelte b/ui/packages/app/src/components/input/DataFrame/DataFrame.svelte index 179fdec9da..8918728b63 100644 --- a/ui/packages/app/src/components/input/DataFrame/DataFrame.svelte +++ b/ui/packages/app/src/components/input/DataFrame/DataFrame.svelte @@ -1,13 +1,11 @@ -

{label}

-
Date: Wed, 16 Feb 2022 10:02:59 +0000 Subject: [PATCH 5/6] More unit tests (#632) * deepCopy tests * add tests for randInt * add test for getNextColor --- .../app/src/components/utils/helpers.test.ts | 83 +++++++++++++++++-- .../app/src/components/utils/helpers.ts | 3 +- 2 files changed, 77 insertions(+), 9 deletions(-) diff --git a/ui/packages/app/src/components/utils/helpers.test.ts b/ui/packages/app/src/components/utils/helpers.test.ts index 8fc30efab3..c7a4590386 100644 --- a/ui/packages/app/src/components/utils/helpers.test.ts +++ b/ui/packages/app/src/components/utils/helpers.test.ts @@ -1,24 +1,93 @@ -import { assert, describe, expect, it } from "vitest"; -import { prettyBytes } from "./helpers"; +import { assert, describe, test } from "vitest"; +import { prettyBytes, deepCopy, randInt, getNextColor } from "./helpers"; describe("prettyBytes", () => { - it("handle B", () => { + test("handle B", () => { assert.equal(prettyBytes(10), "10.0 B"); }); - it("handles KB", () => { + test("handles KB", () => { assert.equal(prettyBytes(1_300), "1.3 KB"); }); - it("handles MB", () => { + test("handles MB", () => { assert.equal(prettyBytes(1_300_000), "1.2 MB"); }); - it("handles GB", () => { + test("handles GB", () => { assert.equal(prettyBytes(1_300_000_123), "1.2 GB"); }); - it("handles PB", () => { + test("handles PB", () => { assert.equal(prettyBytes(1_300_000_123_000), "1.2 PB"); }); }); + +describe("deepCopy", () => { + test("handle arrays", () => { + const array = [1, 2, 3]; + const copy = deepCopy(array); + assert.ok(array !== copy); + assert.deepEqual(array, copy); + }); + + test("handle objects", () => { + const obj = { a: 1, b: 2, c: 3 }; + const copy = deepCopy(obj); + assert.ok(obj !== copy); + assert.deepEqual(obj, copy); + }); + + test("handle complex structures", () => { + const obj = { + a: 1, + b: { + a: 1, + b: { + a: 1, + b: { a: 1, b: 2, c: 3 }, + c: [ + 1, + 2, + { a: 1, b: { a: 1, b: { a: 1, b: 2, c: 3 }, c: [1, 2, 3] } } + ] + }, + c: 3 + }, + c: 3 + }; + const copy = deepCopy(obj); + assert.ok(obj !== copy); + assert.deepEqual(obj, copy); + }); +}); + +describe("randInt", () => { + test("returns a random number", () => { + assert.typeOf(randInt(0, 10), "number"); + }); + + test("respects min and max", () => { + const n = randInt(0, 10); + assert.ok(n >= 0 && n <= 10); + }); + + test("respects min and max when negative", () => { + const n = randInt(-100, -10); + assert.ok(n > -100 && n < -10); + }); +}); + +describe("getNextColor", () => { + test("returns a color", () => { + assert.equal(getNextColor(0), "rgba(255, 99, 132, 1)"); + }); + + test("returns a color when index is very high", () => { + assert.ok( + getNextColor(999999999).match( + /rgba\([0-9]{1,3}, [0-9]{1,3}, [0-9]{1,3}, [0-9]\)/ + ) + ); + }); +}); diff --git a/ui/packages/app/src/components/utils/helpers.ts b/ui/packages/app/src/components/utils/helpers.ts index 1b73115888..2bc224c646 100644 --- a/ui/packages/app/src/components/utils/helpers.ts +++ b/ui/packages/app/src/components/utils/helpers.ts @@ -15,8 +15,7 @@ export function randInt(min: number, max: number): number { return Math.floor(Math.random() * (max - min) + min); } -export const getNextColor = (index: number, alpha?: number): string => { - alpha = alpha || 1; +export const getNextColor = (index: number, alpha: number = 1): string => { let default_colors = [ [255, 99, 132], [54, 162, 235], From 08ef8b0ed5c748250bfe8b6ffec1c63c5b6e81cd Mon Sep 17 00:00:00 2001 From: PythicCoder Date: Wed, 16 Feb 2022 14:21:06 +0200 Subject: [PATCH 6/6] added hebrew json draft --- ui/packages/app/public/lang/he.json | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 ui/packages/app/public/lang/he.json diff --git a/ui/packages/app/public/lang/he.json b/ui/packages/app/public/lang/he.json new file mode 100644 index 0000000000..53f9735861 --- /dev/null +++ b/ui/packages/app/public/lang/he.json @@ -0,0 +1,18 @@ +{ + "interface": { + "submit": "שלח", + "clear": "נקה", + "interpret": "לפרש", + "flag": "סמן", + "examples": "דוגמות", + "drop_image": "גרור קובץ תמונה לכאן", + "drop_video": "גרור קובץ סרטון לכאן", + "drop_audio": "גרור לכאן קובץ שמע", + "drop_file": "גרור קובץ לכאן", + "drop_csv": "גרור csv קובץ לכאן", + "or": "או", + "click_to_upload": "לחץ כדי להעלות", + "view_api": "צפה ב API", + "built_with_Gradio": "בנוי עם גרדיו" + } + } \ No newline at end of file