synkathairo commited on
Commit
5fe3ef5
0 Parent(s):
Files changed (5) hide show
  1. .gitattributes +34 -0
  2. LICENSE +28 -0
  3. README.md +37 -0
  4. app.py +49 -0
  5. requirements.txt +5 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
LICENSE ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2023, synkathairo
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
README.md ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Flan T5 Large Gradio
3
+ emoji: 🐨
4
+ colorFrom: indigo
5
+ colorTo: green
6
+ sdk: gradio
7
+ sdk_version: 3.29.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: bsd-3-clause
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
14
+
15
+ # flan-t5-large-gradio
16
+ A [gradio](https://gradio.app/) frontend for [Google's Flan-T5 Large](https://huggingface.co/google/flan-t5-large) language model, can also be adjusted for other sizes.
17
+
18
+ The gradio frontend runs in the browser, and displays a chat-like interface for interacting with the language model.
19
+
20
+ ## To run:
21
+
22
+ Install the dependencies: gradio, transformers, sentencepiece
23
+
24
+ Recommended to install: safetensors
25
+
26
+ Optionally also install: accelerate
27
+
28
+ Run with: `python app.py`
29
+
30
+ Optionally run with: `accelerate launch app.py`
31
+ (this may or may not speed up your execution)
32
+
33
+ ## To use other size models
34
+
35
+ Modify lines 4-6, comment/uncomment to select a different model. Note that each model has different requirements for storage/RAM, the code as presently configured assumes sufficient RAM to load the entire model.
36
+
37
+ Additional info on loading large models is on the [Hugging Face website](https://huggingface.co/blog/accelerate-large-models), see [also](https://huggingface.co/docs/accelerate/v0.11.0/en/big_modeling)
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import T5Tokenizer, T5ForConditionalGeneration
2
+ import gradio as gr
3
+
4
+ # model_name = "google/flan-t5-small"
5
+ # model_name = "google/flan-t5-base"
6
+ model_name = "google/flan-t5-large"
7
+ # model_name = "google/flan-t5-xl"
8
+
9
+ default_max_length = 200
10
+
11
+ print("Using `{}`.".format(model_name))
12
+
13
+ tokenizer = T5Tokenizer.from_pretrained(model_name)
14
+ print("T5Tokenizer loaded from pretrained.")
15
+
16
+ model = T5ForConditionalGeneration.from_pretrained(model_name, device_map="auto")
17
+ print("T5ForConditionalGeneration loaded from pretrained.")
18
+
19
+
20
+ def inference(max_length, input_text, history=[]):
21
+ input_ids = tokenizer(input_text, return_tensors="pt").input_ids
22
+ outputs = model.generate(input_ids, max_length=max_length, bos_token_id=0)
23
+ result = tokenizer.decode(outputs[0], skip_special_tokens=True)
24
+ history.append((input_text, result))
25
+ return history, history
26
+
27
+
28
+ with gr.Blocks() as demo:
29
+ with gr.Row():
30
+ gr.Markdown(
31
+ "<h1>Demo of {}</h1><p>See more at Hugging Face: <a href='https://huggingface.co/{}'>{}</a>.</p>".format(
32
+ model_name, model_name, model_name
33
+ )
34
+ )
35
+ max_length = gr.Number(
36
+ value=default_max_length, label="maximum length of response"
37
+ )
38
+
39
+ chatbot = gr.Chatbot(label=model_name)
40
+ state = gr.State([])
41
+
42
+ with gr.Row():
43
+ txt = gr.Textbox(
44
+ show_label=False, placeholder="Enter text and press enter"
45
+ ).style(container=False)
46
+
47
+ txt.submit(fn=inference, inputs=[max_length, txt, state], outputs=[chatbot, state])
48
+
49
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio
2
+ transformers
3
+ sentencepiece
4
+ safetensors
5
+ accelerate