Jianbin Chang commited on
Commit
2b6edf9
1 Parent(s): ccb3a5e

feat: init

Browse files
Files changed (2) hide show
  1. app.py +62 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ import torch
4
+
5
+ theme = gr.themes.Monochrome(
6
+ primary_hue="indigo",
7
+ secondary_hue="blue",
8
+ neutral_hue="slate",
9
+ radius_size=gr.themes.sizes.radius_sm,
10
+ font=[gr.themes.GoogleFont("Open Sans"), "ui-sans-serif", "system-ui", "sans-serif"],
11
+ )
12
+
13
+ instruct_pipeline = pipeline(model="databricks/dolly-v2-12b", torch_dtype=torch.bfloat16, trust_remote_code=True, device_map="auto")
14
+ def generate(instruction):
15
+ return instruct_pipeline(instruction)
16
+
17
+
18
+ examples = [
19
+ "Instead of making a peanut butter and jelly sandwich, what else could I combine peanut butter with in a sandwich? Give five ideas",
20
+ "How do I make a campfire?",
21
+ "Write me a tweet about the launch of Dolly 2.0, a new LLM"
22
+ ]
23
+
24
+
25
+ def process_example(args):
26
+ for x in generate(args):
27
+ pass
28
+ return x
29
+
30
+ css = ".generating {visibility: hidden}"
31
+
32
+ with gr.Blocks(theme=theme, analytics_enabled=False, css=css) as demo:
33
+ with gr.Column():
34
+ gr.Markdown(
35
+ """ ## Dolly 2.0
36
+ Dolly 2.0 is a 12B parameter language model based on the EleutherAI pythia model family and fine-tuned exclusively on a new, high-quality human generated instruction following dataset, crowdsourced among Databricks employees. For more details, please refer to the [model card](https://huggingface.co/databricks/dolly-v2-12b)
37
+
38
+ Type in the box below and click the button to generate answers to your most pressing questions!
39
+
40
+ """
41
+ )
42
+ with gr.Row():
43
+ with gr.Column(scale=3):
44
+ instruction = gr.Textbox(placeholder="Enter your question here", label="Question", elem_id="q-input")
45
+
46
+ with gr.Box():
47
+ gr.Markdown("**Answer**")
48
+ output = gr.Markdown(elem_id="q-output")
49
+ submit = gr.Button("Generate", variant="primary")
50
+ gr.Examples(
51
+ examples=examples,
52
+ inputs=[instruction],
53
+ cache_examples=False,
54
+ fn=process_example,
55
+ outputs=[output],
56
+ )
57
+
58
+
59
+ submit.click(generate, inputs=[instruction], outputs=[output])
60
+ instruction.submit(generate, inputs=[instruction], outputs=[output])
61
+
62
+ demo.queue(concurrency_count=16).launch(debug=True)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ transformers
2
+ torch
3
+ accelerate
4
+ gradio