abdullah-tariq commited on
Commit
490823b
1 Parent(s): d38df3e

Add Dolly Chat

Browse files
Files changed (2) hide show
  1. app.py +51 -4
  2. requirements.txt +0 -0
app.py CHANGED
@@ -1,7 +1,54 @@
 
 
 
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
1
+ import os
2
+ from pathlib import Path
3
+
4
  import gradio as gr
5
+ import torch
6
+ from huggingface_hub import snapshot_download
7
+ from transformers import pipeline
8
+
9
+ model_name = "databricks/dolly-v2-12b"
10
+
11
+ local_dir = f"./models/{model_name}"
12
+ if not Path(local_dir).exists() or len(os.listdir(local_dir)) == 0:
13
+ snapshot_download(model_name, local_dir=local_dir)
14
+
15
+ generate_text = pipeline(model=local_dir, torch_dtype=torch.bfloat16, trust_remote_code=True,
16
+ device_map="auto")
17
+
18
+ theme = gr.themes.Monochrome(
19
+ primary_hue="indigo",
20
+ secondary_hue="blue",
21
+ neutral_hue="slate",
22
+ radius_size=gr.themes.sizes.radius_sm,
23
+ font=[gr.themes.GoogleFont("Open Sans"), "ui-sans-serif", "system-ui", "sans-serif"],
24
+ )
25
+
26
+ with gr.Blocks(theme=theme) as demo:
27
+ chatbot = gr.Chatbot()
28
+ msg = gr.Textbox()
29
+ clear = gr.Button("Clear")
30
+
31
+
32
+ def user(user_message, history):
33
+ return "", history + [[user_message, None]]
34
+
35
+
36
+ def bot(history):
37
+ history[-1][1] = generate_text(history[-1][0])
38
+ return history
39
+
40
+
41
+ msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
42
+ bot, chatbot, chatbot
43
+ )
44
+ clear.click(lambda: None, None, chatbot, queue=False)
45
+
46
+ if __name__ == "__main__":
47
+ demo.launch(server_name="0.0.0.0", server_port=3000)
48
+
49
 
50
+ # def greet(name):
51
+ # return "Hello " + name + "!!"
52
 
53
+ # iface = gr.Interface(fn=greet, inputs="text", outputs="text")
54
+ # iface.launch()
requirements.txt ADDED
File without changes