awacke1 commited on
Commit
cdc8845
1 Parent(s): 297a56e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +148 -5
app.py CHANGED
@@ -1,19 +1,162 @@
1
-
2
  from datasets import load_dataset
3
-
4
  #LOINC
5
  datasetLOINC = load_dataset("awacke1/LOINC-CodeSet-Value-Description.csv")
6
-
7
  #SNOMED:
8
  datasetSNOMED = load_dataset("awacke1/SNOMED-CT-Code-Value-Semantic-Set.csv")
9
-
10
  #eCQM:
11
  dataseteCQM = load_dataset("awacke1/eCQM-Code-Value-Semantic-Set.csv")
12
-
13
  print(datasetLOINC)
14
  print(datasetSNOMED)
15
  print(dataseteCQM)
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
  #-or-
19
  #git lfs install
 
 
1
  from datasets import load_dataset
 
2
  #LOINC
3
  datasetLOINC = load_dataset("awacke1/LOINC-CodeSet-Value-Description.csv")
 
4
  #SNOMED:
5
  datasetSNOMED = load_dataset("awacke1/SNOMED-CT-Code-Value-Semantic-Set.csv")
 
6
  #eCQM:
7
  dataseteCQM = load_dataset("awacke1/eCQM-Code-Value-Semantic-Set.csv")
 
8
  print(datasetLOINC)
9
  print(datasetSNOMED)
10
  print(dataseteCQM)
11
 
12
+ import os
13
+ import json
14
+ import numpy as np
15
+ import gradio as gr
16
+
17
+ CHOICES = ["foo", "bar", "baz"]
18
+ JSONOBJ = """{"items":{"item":[{"id": "0001","type": null,"is_good": false,"ppu": 0.55,"batters":{"batter":[{ "id": "1001", "type": "Regular" },{ "id": "1002", "type": "Chocolate" },{ "id": "1003", "type": "Blueberry" },{ "id": "1004", "type": "Devil's Food" }]},"topping":[{ "id": "5001", "type": "None" },{ "id": "5002", "type": "Glazed" },{ "id": "5005", "type": "Sugar" },{ "id": "5007", "type": "Powdered Sugar" },{ "id": "5006", "type": "Chocolate with Sprinkles" },{ "id": "5003", "type": "Chocolate" },{ "id": "5004", "type": "Maple" }]}]}}"""
19
+
20
+
21
+ def fn(
22
+ text1,
23
+ text2,
24
+ num,
25
+ slider1,
26
+ slider2,
27
+ single_checkbox,
28
+ checkboxes,
29
+ radio,
30
+ dropdown,
31
+ im1,
32
+ im2,
33
+ im3,
34
+ im4,
35
+ video,
36
+ audio1,
37
+ audio2,
38
+ file,
39
+ df1,
40
+ df2,
41
+ ):
42
+ return (
43
+ (text1 if single_checkbox else text2)
44
+ + ", selected:"
45
+ + ", ".join(checkboxes), # Text
46
+ {
47
+ "positive": num / (num + slider1 + slider2),
48
+ "negative": slider1 / (num + slider1 + slider2),
49
+ "neutral": slider2 / (num + slider1 + slider2),
50
+ }, # Label
51
+ (audio1[0], np.flipud(audio1[1]))
52
+ if audio1 is not None else os.path.join(os.path.dirname(__file__), "files/cantina.wav"), # Audio
53
+ np.flipud(im1)
54
+ if im1 is not None else os.path.join(os.path.dirname(__file__), "files/cheetah1.jpg"), # Image
55
+ video
56
+ if video is not None else os.path.join(os.path.dirname(__file__), "files/world.mp4"), # Video
57
+ [
58
+ ("The", "art"),
59
+ ("quick brown", "adj"),
60
+ ("fox", "nn"),
61
+ ("jumped", "vrb"),
62
+ ("testing testing testing", None),
63
+ ("over", "prp"),
64
+ ("the", "art"),
65
+ ("testing", None),
66
+ ("lazy", "adj"),
67
+ ("dogs", "nn"),
68
+ (".", "punc"),
69
+ ] + [(f"test {x}", f"test {x}") for x in range(10)], # HighlightedText
70
+ [
71
+ ("The testing testing testing", None),
72
+ ("over", 0.6),
73
+ ("the", 0.2),
74
+ ("testing", None),
75
+ ("lazy", -0.1),
76
+ ("dogs", 0.4),
77
+ (".", 0),
78
+ ] + [(f"test", x / 10) for x in range(-10, 10)], # HighlightedText
79
+ json.loads(JSONOBJ), # JSON
80
+ "<button style='background-color: red'>Click Me: " + radio + "</button>", # HTML
81
+ os.path.join(os.path.dirname(__file__), "files/titanic.csv"),
82
+ df1, # Dataframe
83
+ np.random.randint(0, 10, (4, 4)), # Dataframe
84
+ df2, # Timeseries
85
+ )
86
+
87
+
88
+ demo = gr.Interface(
89
+ fn,
90
+ inputs=[
91
+ gr.Textbox(value="Lorem ipsum", label="Textbox"),
92
+ gr.Textbox(lines=3, placeholder="Type here..", label="Textbox 2"),
93
+ gr.Number(label="Number", value=42),
94
+ gr.Slider(10, 20, value=15, label="Slider: 10 - 20"),
95
+ gr.Slider(maximum=20, step=0.04, label="Slider: step @ 0.04"),
96
+ gr.Checkbox(label="Checkbox"),
97
+ gr.CheckboxGroup(label="CheckboxGroup", choices=CHOICES, value=CHOICES[0:2]),
98
+ gr.Radio(label="Radio", choices=CHOICES, value=CHOICES[2]),
99
+ gr.Dropdown(label="Dropdown", choices=CHOICES),
100
+ gr.Image(label="Image"),
101
+ gr.Image(label="Image w/ Cropper", tool="select"),
102
+ gr.Image(label="Sketchpad", source="canvas"),
103
+ gr.Image(label="Webcam", source="webcam"),
104
+ gr.Video(label="Video"),
105
+ gr.Audio(label="Audio"),
106
+ gr.Audio(label="Microphone", source="microphone"),
107
+ gr.File(label="File"),
108
+ gr.Dataframe(label="Dataframe", headers=["Name", "Age", "Gender"]),
109
+ gr.Timeseries(x="time", y=["price", "value"], colors=["pink", "purple"]),
110
+ ],
111
+ outputs=[
112
+ gr.Textbox(label="Textbox"),
113
+ gr.Label(label="Label"),
114
+ gr.Audio(label="Audio"),
115
+ gr.Image(label="Image"),
116
+ gr.Video(label="Video"),
117
+ gr.HighlightedText(label="HighlightedText", color_map={"punc": "pink", "test 0": "blue"}),
118
+ gr.HighlightedText(label="HighlightedText", show_legend=True),
119
+ gr.JSON(label="JSON"),
120
+ gr.HTML(label="HTML"),
121
+ gr.File(label="File"),
122
+ gr.Dataframe(label="Dataframe"),
123
+ gr.Dataframe(label="Numpy"),
124
+ gr.Timeseries(x="time", y=["price", "value"], label="Timeseries"),
125
+ ],
126
+ examples=[
127
+ [
128
+ "the quick brown fox",
129
+ "jumps over the lazy dog",
130
+ 10,
131
+ 12,
132
+ 4,
133
+ True,
134
+ ["foo", "baz"],
135
+ "baz",
136
+ "bar",
137
+ os.path.join(os.path.dirname(__file__), "files/cheetah1.jpg"),
138
+ os.path.join(os.path.dirname(__file__), "files/cheetah1.jpg"),
139
+ os.path.join(os.path.dirname(__file__), "files/cheetah1.jpg"),
140
+ os.path.join(os.path.dirname(__file__), "files/cheetah1.jpg"),
141
+ os.path.join(os.path.dirname(__file__), "files/world.mp4"),
142
+ os.path.join(os.path.dirname(__file__), "files/cantina.wav"),
143
+ os.path.join(os.path.dirname(__file__), "files/cantina.wav"),
144
+ os.path.join(os.path.dirname(__file__), "files/titanic.csv"),
145
+ [[1, 2, 3], [3, 4, 5]],
146
+ os.path.join(os.path.dirname(__file__), "files/time.csv"),
147
+ ]
148
+ ]
149
+ * 3,
150
+ theme="default",
151
+ title="Gradio AI UI UX",
152
+ cache_examples=False,
153
+ description="Try out all the components!",
154
+ article="Learn more about [Gradio](http://gradio.app)",
155
+ )
156
+
157
+ if __name__ == "__main__":
158
+ demo.launch()
159
+
160
 
161
  #-or-
162
  #git lfs install