Spaces:
Runtime error
Runtime error
Jason Adrian
commited on
Commit
·
2746b21
1
Parent(s):
c3bfbdb
first commit
Browse files- __pycache__/gradio.cpython-310.pyc +0 -0
- app.py +61 -0
- requirements.txt +63 -0
__pycache__/gradio.cpython-310.pyc
ADDED
Binary file (163 Bytes). View file
|
|
app.py
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import random
|
3 |
+
|
4 |
+
class_names = ['cat', 'dog']
|
5 |
+
|
6 |
+
def UpdateDropdown(className):
|
7 |
+
class_names.append(className)
|
8 |
+
return gr.Dropdown.update(choices=class_names)
|
9 |
+
|
10 |
+
def showPickedClass(className):
|
11 |
+
return className
|
12 |
+
|
13 |
+
def image_classifier(inp):
|
14 |
+
if inp is None:
|
15 |
+
return {'cat': 0.3, 'dog': 0.7}
|
16 |
+
|
17 |
+
num_class = len(class_names)
|
18 |
+
|
19 |
+
# Generate random percentages between 0 and 1
|
20 |
+
percentages = [random.random() for _ in range(num_class)]
|
21 |
+
total = sum(percentages)
|
22 |
+
|
23 |
+
# Normalize the percentages to ensure they sum up to 1
|
24 |
+
normalized_percentages = [p / total for p in percentages]
|
25 |
+
|
26 |
+
labeled_result = {name:score for name, score in zip(class_names, normalized_percentages)}
|
27 |
+
|
28 |
+
return labeled_result, gr.Dropdown.update(choices=class_names)
|
29 |
+
|
30 |
+
demo = gr.Blocks()
|
31 |
+
|
32 |
+
with demo as app:
|
33 |
+
with gr.Row():
|
34 |
+
with gr.Column():
|
35 |
+
inp_img = gr.Image()
|
36 |
+
with gr.Row():
|
37 |
+
clear_btn = gr.Button(value="Clear")
|
38 |
+
process_btn = gr.Button(value="Process", variant="primary")
|
39 |
+
with gr.Column():
|
40 |
+
out_txt = gr.Label(label="Probabilities", num_top_classes=3)
|
41 |
+
|
42 |
+
text_input = gr.Textbox(label="Input the new class here")
|
43 |
+
b1 = gr.Button("Add new class")
|
44 |
+
|
45 |
+
text_options = gr.Dropdown(class_names, label="Class Label", multiselect=False)
|
46 |
+
b2 = gr.Button("Show me the picked class")
|
47 |
+
picked_class = gr.Textbox()
|
48 |
+
|
49 |
+
b1.click(UpdateDropdown, inputs=text_input, outputs=text_options)
|
50 |
+
b2.click(showPickedClass, inputs=text_options, outputs=picked_class)
|
51 |
+
|
52 |
+
process_btn.click(image_classifier, inputs=inp_img, outputs=[out_txt, text_options])
|
53 |
+
clear_btn.click(lambda:(
|
54 |
+
gr.update(value=None),
|
55 |
+
gr.update(value=None)
|
56 |
+
),
|
57 |
+
inputs=None,
|
58 |
+
outputs=[inp_img, out_txt])
|
59 |
+
|
60 |
+
|
61 |
+
demo.launch(debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
aiofiles==23.2.1
|
2 |
+
altair==5.1.2
|
3 |
+
annotated-types==0.6.0
|
4 |
+
anyio==3.7.1
|
5 |
+
attrs==23.1.0
|
6 |
+
certifi==2023.7.22
|
7 |
+
charset-normalizer==3.3.0
|
8 |
+
click==8.1.7
|
9 |
+
colorama==0.4.6
|
10 |
+
contourpy==1.1.1
|
11 |
+
cycler==0.12.1
|
12 |
+
exceptiongroup==1.1.3
|
13 |
+
fastapi==0.103.2
|
14 |
+
ffmpy==0.3.1
|
15 |
+
filelock==3.12.4
|
16 |
+
fonttools==4.43.1
|
17 |
+
fsspec==2023.9.2
|
18 |
+
gradio==3.47.1
|
19 |
+
gradio_client==0.6.0
|
20 |
+
h11==0.14.0
|
21 |
+
httpcore==0.18.0
|
22 |
+
httpx==0.25.0
|
23 |
+
huggingface-hub==0.17.3
|
24 |
+
idna==3.4
|
25 |
+
importlib-resources==6.1.0
|
26 |
+
Jinja2==3.1.2
|
27 |
+
jsonschema==4.19.1
|
28 |
+
jsonschema-specifications==2023.7.1
|
29 |
+
kiwisolver==1.4.5
|
30 |
+
MarkupSafe==2.1.3
|
31 |
+
matplotlib==3.8.0
|
32 |
+
mpmath==1.3.0
|
33 |
+
networkx==3.1
|
34 |
+
numpy==1.26.0
|
35 |
+
orjson==3.9.7
|
36 |
+
packaging==23.2
|
37 |
+
pandas==2.1.1
|
38 |
+
Pillow==10.0.1
|
39 |
+
pydantic==2.4.2
|
40 |
+
pydantic_core==2.10.1
|
41 |
+
pydub==0.25.1
|
42 |
+
pyparsing==3.1.1
|
43 |
+
python-dateutil==2.8.2
|
44 |
+
python-multipart==0.0.6
|
45 |
+
pytz==2023.3.post1
|
46 |
+
PyYAML==6.0.1
|
47 |
+
referencing==0.30.2
|
48 |
+
requests==2.31.0
|
49 |
+
rpds-py==0.10.4
|
50 |
+
semantic-version==2.10.0
|
51 |
+
six==1.16.0
|
52 |
+
sniffio==1.3.0
|
53 |
+
starlette==0.27.0
|
54 |
+
sympy==1.12
|
55 |
+
toolz==0.12.0
|
56 |
+
torch==2.1.0
|
57 |
+
torchvision==0.16.0
|
58 |
+
tqdm==4.66.1
|
59 |
+
typing_extensions==4.8.0
|
60 |
+
tzdata==2023.3
|
61 |
+
urllib3==2.0.6
|
62 |
+
uvicorn==0.23.2
|
63 |
+
websockets==11.0.3
|