yourusername commited on
Commit
0804f04
1 Parent(s): ec08b42

:sparkles: add a couple apps

Browse files
Files changed (7) hide show
  1. .gitignore +162 -0
  2. README.md +1 -0
  3. app.py +10 -16
  4. chatbot/app.py +35 -0
  5. packages.txt +3 -0
  6. pictionary/app.py +47 -0
  7. requirements.txt +7 -1
.gitignore ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
159
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
+ #.idea/
161
+
162
+ .DS_Store
README.md CHANGED
@@ -4,6 +4,7 @@ emoji: 🤗
4
  colorFrom: blue
5
  colorTo: red
6
  sdk: gradio
 
7
  app_file: app.py
8
  pinned: false
9
  ---
 
4
  colorFrom: blue
5
  colorTo: red
6
  sdk: gradio
7
+ sdk_version: 2.9b23
8
  app_file: app.py
9
  pinned: false
10
  ---
app.py CHANGED
@@ -1,18 +1,12 @@
1
  import gradio as gr
2
 
3
-
4
- def main(text):
5
- # A gradio function that lowercases text and returns it
6
- return text.lower()
7
-
8
-
9
- # A simple gradio app for text
10
- app = gr.Interface(
11
- main,
12
- inputs="text",
13
- outputs="text",
14
- title="gradio-guides",
15
- description="A collection of gradio apps from the gradio guides",
16
- )
17
- app.launch(debug=True)
18
-
 
1
  import gradio as gr
2
 
3
+ import chatbot.app
4
+ import pictionary.app
5
+
6
+ gr.TabbedInterface(
7
+ interface_list=[
8
+ chatbot.app.interface,
9
+ pictionary.app.interface,
10
+ ],
11
+ tab_names=['chatbot', 'pictionary'],
12
+ ).launch(debug=True)
 
 
 
 
 
 
chatbot/app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+
4
+ tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-medium")
5
+ model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-medium")
6
+
7
+
8
+ def predict(input, history=[]):
9
+ # tokenize the new input sentence
10
+ new_user_input_ids = tokenizer.encode(input + tokenizer.eos_token, return_tensors='pt')
11
+
12
+ # append the new user input tokens to the chat history
13
+ bot_input_ids = torch.cat([torch.LongTensor(history), new_user_input_ids], dim=-1)
14
+
15
+ # generate a response
16
+ history = model.generate(bot_input_ids, max_length=1000, pad_token_id=tokenizer.eos_token_id).tolist()
17
+
18
+ # convert the tokens to text, and then split the responses into the right format
19
+ response = tokenizer.decode(history[0]).split("<|endoftext|>")
20
+ response = [(response[i], response[i + 1]) for i in range(0, len(response) - 1, 2)] # convert to tuples of list
21
+ return response, history
22
+
23
+
24
+ import gradio as gr
25
+
26
+ interface = gr.Interface(
27
+ fn=predict,
28
+ theme="default",
29
+ css=".footer {display:none !important}",
30
+ inputs=["text", "state"],
31
+ outputs=["chatbot", "state"],
32
+ )
33
+
34
+ if __name__ == '__main__':
35
+ interface.launch()
packages.txt CHANGED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ ffmpeg
2
+ libsm6
3
+ libxext6
pictionary/app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+
3
+ import gradio as gr
4
+ import torch
5
+ from huggingface_hub import hf_hub_download
6
+ from torch import nn
7
+
8
+ LABELS = Path(hf_hub_download('nateraw/quickdraw', 'class_names.txt')).read_text().splitlines()
9
+
10
+ model = nn.Sequential(
11
+ nn.Conv2d(1, 32, 3, padding='same'),
12
+ nn.ReLU(),
13
+ nn.MaxPool2d(2),
14
+ nn.Conv2d(32, 64, 3, padding='same'),
15
+ nn.ReLU(),
16
+ nn.MaxPool2d(2),
17
+ nn.Conv2d(64, 128, 3, padding='same'),
18
+ nn.ReLU(),
19
+ nn.MaxPool2d(2),
20
+ nn.Flatten(),
21
+ nn.Linear(1152, 256),
22
+ nn.ReLU(),
23
+ nn.Linear(256, len(LABELS)),
24
+ )
25
+ weights_file = hf_hub_download('nateraw/quickdraw', 'pytorch_model.bin')
26
+ state_dict = torch.load(weights_file, map_location='cpu')
27
+ model.load_state_dict(state_dict, strict=False)
28
+ model.eval()
29
+
30
+
31
+ def predict(im):
32
+ x = torch.tensor(im, dtype=torch.float32).unsqueeze(0).unsqueeze(0) / 255.0
33
+
34
+ with torch.no_grad():
35
+ out = model(x)
36
+
37
+ probabilities = torch.nn.functional.softmax(out[0], dim=0)
38
+
39
+ values, indices = torch.topk(probabilities, 5)
40
+
41
+ return {LABELS[i]: v.item() for i, v in zip(indices, values)}
42
+
43
+
44
+ interface = gr.Interface(predict, inputs='sketchpad', outputs='label', live=True)
45
+
46
+ if __name__ == '__main__':
47
+ interface.launch(debug=True)
requirements.txt CHANGED
@@ -1,2 +1,8 @@
1
  gradio
2
-
 
 
 
 
 
 
 
1
  gradio
2
+ torch
3
+ transformers
4
+ opencv-python
5
+ onnxruntime==1.6.0
6
+ numpy
7
+ matplotlib
8
+ onnx