Skip to content

Commit 5d51fbc

Browse files
dawoodkhan82gradio-pr-botabidlabshannahblairduerrsimon
authored
Fixes Drag and Drop for Upload (#6525)
* fix * add changeset * tests * Update package.json * Hotfix: version on changelog (#6559) * clog version * add changeset --------- Co-authored-by: gradio-pr-bot <[email protected]> * Fix version in other changelog (#6561) * Fix version in other changelog why do we have 2? * remove changeset * Ensure Chatbot messages are properly aligned when `rtl` is true (#6574) * fix text alignment when rtl is true * add changeset --------- Co-authored-by: gradio-pr-bot <[email protected]> * Improve like/dislike functionality (#6572) * amend like/dislike logic * add like/dislike to chatbot demo and add e2e test * add changeset * e2e test changes * revert chatbot_component changes * tweak * generate notebooks * tweak --------- Co-authored-by: gradio-pr-bot <[email protected]> * Fix typo envrion -> environ (#6585) * Feat: make UploadButton accept icon (#6584) * feat: make UploadButton accept icon * add changeset * add proxy url prop * add stories --------- Co-authored-by: Abubakar Abid <[email protected]> Co-authored-by: gradio-pr-bot <[email protected]> * Make FileExplorer work on python 3.8 and 3.9. Also make it update on changes to root, glob, or glob_dir (#6550) * Add code * add changeset * add changeset * Add test * fix --------- Co-authored-by: gradio-pr-bot <[email protected]> * Fix uploaded file wasn't moved to custom temp dir at different disks (#6565) * Fix uploaded file wasn't moved to custom temp dir at different disks * add changeset * Update routes.py --------- Co-authored-by: gradio-pr-bot <[email protected]> Co-authored-by: Freddy Boulton <[email protected]> * Fix the docstring decoration (#5885) * Fix the docstring of the `Slider` class * add changeset * Update the JSON file generator to output a new field .styled_description to render the inline code syntax in the description field * add changeset * Update style_types() to deal with backticks and single asterisks * Update the inline style converter to use regex for the curly bracket syntax as well * Revert `style_types()` not to touch the `description` field and update the frontend code to apply styling to such formatted texts on Svelte's side * Apply the inline styler to other `.description` field appearances * Apply the inline styler to `.preprocessing`, `.postprocessing`, `.examples-format`, `.events`, and `*.parameters.doc` * Stop applying HTML styles to the JSON data, instaed apply HTML escaping * Escape HTML tokens in .parameters[]["doc"] too * fixes --------- Co-authored-by: gradio-pr-bot <[email protected]> Co-authored-by: Ali Abdalla <[email protected]> * chore(deps): update all non-major dependencies (#6593) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency jsdom to v23 (#6582) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Abubakar Abid <[email protected]> * Update zh-CN.json (#6512) * Update zh-CN.json * add changeset * format --------- Co-authored-by: gradio-pr-bot <[email protected]> Co-authored-by: Abubakar Abid <[email protected]> * Fix: Gradio Client work with private Spaces (#6602) * client with private space * add changeset * lint * add test --------- Co-authored-by: gradio-pr-bot <[email protected]> * Update file_explorer.py - Fixing error if nothing selected in file_count=single mode (return None rather) (#6607) * Update file_explorer.py Fixing error if nothing selected in file_count=single mode (return None rather) * add changeset * added unit tests --------- Co-authored-by: Abubakar Abid <[email protected]> Co-authored-by: gradio-pr-bot <[email protected]> * Remove 2 slider demos from docs (#6624) * remove 2 slider demos * add changeset --------- Co-authored-by: gradio-pr-bot <[email protected]> * Fix encoding issue #6364 of reload mode (#6622) * fix: configure default encoding as utf-8 * apply doc change for the fix * apply cn doc change for the fix * add changeset * Lint --------- Co-authored-by: Freddy Boulton <[email protected]> Co-authored-by: gradio-pr-bot <[email protected]> * Quick Image + Text Component Fixes (#6635) * fixes * add changeset --------- Co-authored-by: gradio-pr-bot <[email protected]> * Improve video trimming and error handling (#6566) * amend trimming logic and return original file when error occurs * add interactive story test * add changeset * add changeset --------- Co-authored-by: gradio-pr-bot <[email protected]> * Add `show_recording_waveform` to Audio (#6551) * add show_recording_waveform * add changeset * add animation * Refactor audio component and waveform options * formatting * add margin before audio controls * amend default values * expose gr.WaveformOptions * Tweak waveform options types and handle none * add waveform_options to reverse_audio * tweak bool typing * notebook --------- Co-authored-by: gradio-pr-bot <[email protected]> Co-authored-by: Abubakar Abid <[email protected]> * chore(deps): update dependency chromatic to v10 (#6619) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update chromaui/action action to v10 (#6618) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Add concurrency_limit to ChatInterface, add IDE support for concurrency_limit (#6653) * concurrency limit chat interface * add changeset * Update gradio/chat_interface.py Co-authored-by: Abubakar Abid <[email protected]> --------- Co-authored-by: gradio-pr-bot <[email protected]> Co-authored-by: Abubakar Abid <[email protected]> * format (#6658) * Removes smooth scrolling from website (#6650) * smooth scrolling with css * add changeset * formatting * remove smooth scrolling * add changeset --------- Co-authored-by: gradio-pr-bot <[email protected]> * chore: update versions (#6575) Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * Fix reload mode warning about not being able to find the app (#6660) * Fix warning * add changeset * Use * --------- Co-authored-by: gradio-pr-bot <[email protected]> * Update HF token used in CI tests (#6671) * fix tests * format * fixes * add changeset * fixes * fix * fix * update * update * test client * format * hf token 2 * add changeset * add env * add envs * tests * env * fixes * test external * add changeset --------- Co-authored-by: gradio-pr-bot <[email protected]> * use gr.Error for audio length errors (#6672) * use gr.Error for audio length errors * add changeset --------- Co-authored-by: gradio-pr-bot <[email protected]> * Issue 5245: consolidate usage of requests and httpx (#6598) * issue 5245 commit 1 * formatted * add changeset * fixes * fixes * make changes in client too * remove requests from client * add changeset * add changeset * Fixes to test_utils.py in client * fixes in client utils.py and test_utils.py --------- Co-authored-by: gradio-pr-bot <[email protected]> Co-authored-by: Abubakar Abid <[email protected]> * Remove Discourse Forum Link from Website (#6679) * remove forum link * add changeset --------- Co-authored-by: gradio-pr-bot <[email protected]> * Tweak to our bug issue template (#6677) * template * add timeouts * add changeset --------- Co-authored-by: gradio-pr-bot <[email protected]> * Set gradio api server from env (#6666) * Use GRADIO_API_SERVER env * Format the code * add changeset * Use env GRADIO_SHARE_SERVER_ADDRESS as default share_server_address --------- Co-authored-by: gradio-pr-bot <[email protected]> Co-authored-by: Abubakar Abid <[email protected]> * Render each app in the PR's spaces preview in a separate page (#6657) * Use template response * minor fix * Return type hint * add changeset * Remove return types * response_class=None * Use relative path * SPA * remove pydantic pin * Revert * delete changeset * Overflow hidden on body * text gray * Collapsible sidebar * max-height * Use search params * document.location.search --------- Co-authored-by: gradio-pr-bot <[email protected]> * perf guide (#6673) * switch from black to ruff formatter (#6543) * migrate from black to ruff * fix script and dependencies * applying ruff * add changeset * add changeset * address ruff feedback * replace linter * fixed typing * fix typing --------- Co-authored-by: Abubakar Abid <[email protected]> Co-authored-by: gradio-pr-bot <[email protected]> * Cause `gr.ClearButton` to reset the value of `gr.State` (#6680) * state * note * add changeset * buttons * clear button * lint * if * clear' * reset state * fix test --------- Co-authored-by: gradio-pr-bot <[email protected]> * Fix dropdown blur bug when values are provided as tuples (#6694) * fix dropdown blur bug * add changeset --------- Co-authored-by: gradio-pr-bot <[email protected]> * type fix * test * Remove the styles from the Image/Video primitive components and Fix the container styles (#6726) * Remove the styles from the Image/Video primitive components and Fix the container styles * add changeset * Fix image example size styles * Remove border from image/Example with type=gallery --------- Co-authored-by: gradio-pr-bot <[email protected]> * test fix * add changeset * test fix * add changeset * test * test fix * test fix audio video * format * fix obj file issue --------- Co-authored-by: gradio-pr-bot <[email protected]> Co-authored-by: Abubakar Abid <[email protected]> Co-authored-by: Hannah <[email protected]> Co-authored-by: Simon Duerr <[email protected]> Co-authored-by: Xiang Liao <[email protected]> Co-authored-by: Freddy Boulton <[email protected]> Co-authored-by: Dody Suria Wijaya <[email protected]> Co-authored-by: Yuichiro Tachibana (Tsuchiya) <[email protected]> Co-authored-by: Ali Abdalla <[email protected]> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: yanlin <[email protected]> Co-authored-by: v-chabaux <[email protected]> Co-authored-by: Lihao Lei <[email protected]> Co-authored-by: pngwn <[email protected]> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: cswamy <[email protected]> Co-authored-by: aisensiy <[email protected]> Co-authored-by: D V <[email protected]>
1 parent 34f9431 commit 5d51fbc

File tree

4 files changed

+52
-12
lines changed

4 files changed

+52
-12
lines changed

.changeset/modern-clubs-march.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@gradio/model3d": patch
3+
"@gradio/upload": patch
4+
"gradio": patch
5+
---
6+
7+
fix:Fixes Drag and Drop for Upload

js/app/test/model3d_component_events.spec.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { test, expect } from "@gradio/tootils";
1+
import { test, expect, drag_and_drop_file } from "@gradio/tootils";
22

33
test("Model3D click-to-upload uploads file successfuly. Upload and clear events work correctly. Downloading works.", async ({
44
page
@@ -25,3 +25,17 @@ test("Model3D click-to-upload uploads file successfuly. Upload and clear events
2525
const download = await downloadPromise;
2626
await expect(download.suggestedFilename()).toBe("face.obj");
2727
});
28+
29+
test("Model3D drag-and-drop uploads a file to the server correctly.", async ({
30+
page
31+
}) => {
32+
await drag_and_drop_file(
33+
page,
34+
"input[type=file]",
35+
"./test/files/face.obj",
36+
"face.obj"
37+
);
38+
await page.waitForResponse("**/upload?*");
39+
await expect(page.getByLabel("# Change Events")).toHaveValue("1");
40+
await expect(page.getByLabel("# Upload Events")).toHaveValue("1");
41+
});

js/model3D/shared/Model3DUpload.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
<Upload
110110
on:load={handle_upload}
111111
{root}
112-
filetype=".obj, .gltf, .glb"
112+
filetype={[".obj", ".gltf", ".glb", "model/obj"]}
113113
bind:dragging
114114
>
115115
<slot />

js/upload/src/Upload.svelte

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { _ } from "svelte-i18n";
66
import UploadProgress from "./UploadProgress.svelte";
77
8-
export let filetype: string | null = null;
8+
export let filetype: string | string[] | null = null;
99
export let dragging = false;
1010
export let boundedheight = true;
1111
export let center = true;
@@ -20,6 +20,7 @@
2020
2121
let upload_id: string;
2222
let file_data: FileData[];
23+
let accept_file_types: string | null;
2324
2425
// Needed for wasm support
2526
const upload_fn = getContext<typeof upload_files>("upload_files");
@@ -28,6 +29,17 @@
2829
2930
const dispatch = createEventDispatcher();
3031
32+
$: if (filetype == null || typeof filetype === "string") {
33+
accept_file_types = filetype;
34+
} else {
35+
filetype = filetype.map((x) => {
36+
if (x.startsWith(".")) {
37+
return x;
38+
}
39+
return x + "/*";
40+
});
41+
accept_file_types = filetype.join(", ");
42+
}
3143
function updateDragging(): void {
3244
dragging = !dragging;
3345
}
@@ -76,17 +88,23 @@
7688
}
7789
7890
function is_valid_mimetype(
79-
file_accept: string | null,
91+
file_accept: string | string[] | null,
8092
mime_type: string
8193
): boolean {
82-
if (!file_accept) {
94+
if (!file_accept || file_accept === "*" || file_accept === "file/*") {
8395
return true;
8496
}
85-
if (file_accept === "*") {
86-
return true;
97+
if (typeof file_accept === "string" && file_accept.endsWith("/*")) {
98+
file_accept = file_accept.split(",");
8799
}
88-
if (file_accept.endsWith("/*")) {
89-
return mime_type.startsWith(file_accept.slice(0, -1));
100+
if (Array.isArray(file_accept)) {
101+
return (
102+
file_accept.includes(mime_type) ||
103+
file_accept.some((type) => {
104+
const [category] = type.split("/");
105+
return type.endsWith("/*") && mime_type.startsWith(category + "/");
106+
})
107+
);
90108
}
91109
return file_accept === mime_type;
92110
}
@@ -96,13 +114,14 @@
96114
if (!e.dataTransfer?.files) return;
97115
98116
const files_to_load = Array.from(e.dataTransfer.files).filter((f) => {
99-
if (filetype?.split(",").some((m) => is_valid_mimetype(m, f.type))) {
117+
const file_extension =
118+
f.type !== "" ? f.type : "." + f.name.split(".").pop();
119+
if (file_extension && is_valid_mimetype(filetype, file_extension)) {
100120
return true;
101121
}
102122
dispatch("error", `Invalid file type only ${filetype} allowed.`);
103123
return false;
104124
});
105-
106125
await load_files(files_to_load);
107126
}
108127
</script>
@@ -137,7 +156,7 @@
137156
type="file"
138157
bind:this={hidden_upload}
139158
on:change={load_files_from_upload}
140-
accept={filetype}
159+
accept={accept_file_types}
141160
multiple={file_count === "multiple" || undefined}
142161
webkitdirectory={file_count === "directory" || undefined}
143162
mozdirectory={file_count === "directory" || undefined}

0 commit comments

Comments
 (0)