Spaces:
Runtime error
Runtime error
updating code
Browse files- blender_bot.ipynb +0 -148
- blender_bot.py +20 -0
blender_bot.ipynb
DELETED
@@ -1,148 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"nbformat": 4,
|
3 |
-
"nbformat_minor": 0,
|
4 |
-
"metadata": {
|
5 |
-
"colab": {
|
6 |
-
"name": "blender-agent.ipynb",
|
7 |
-
"private_outputs": true,
|
8 |
-
"provenance": [],
|
9 |
-
"collapsed_sections": []
|
10 |
-
},
|
11 |
-
"kernelspec": {
|
12 |
-
"name": "python3",
|
13 |
-
"display_name": "Python 3"
|
14 |
-
},
|
15 |
-
"language_info": {
|
16 |
-
"name": "python"
|
17 |
-
},
|
18 |
-
"accelerator": "GPU"
|
19 |
-
},
|
20 |
-
"cells": [
|
21 |
-
{
|
22 |
-
"cell_type": "markdown",
|
23 |
-
"metadata": {
|
24 |
-
"id": "rJ-QA0ODU4x9"
|
25 |
-
},
|
26 |
-
"source": [
|
27 |
-
"# Install Dependancies"
|
28 |
-
]
|
29 |
-
},
|
30 |
-
{
|
31 |
-
"cell_type": "code",
|
32 |
-
"metadata": {
|
33 |
-
"id": "Bx20ocfPWAYS"
|
34 |
-
},
|
35 |
-
"source": [
|
36 |
-
"#install pytorch\n",
|
37 |
-
"!pip3 install torch==1.9.1+cu111 torchvision==0.10.1+cu111 torchaudio===0.9.1 -f https://download.pytorch.org/whl/torch_stable.html"
|
38 |
-
],
|
39 |
-
"execution_count": null,
|
40 |
-
"outputs": []
|
41 |
-
},
|
42 |
-
{
|
43 |
-
"cell_type": "code",
|
44 |
-
"metadata": {
|
45 |
-
"id": "UcY5FPNHY72K"
|
46 |
-
},
|
47 |
-
"source": [
|
48 |
-
"#install transformers\n",
|
49 |
-
"!pip install transformers"
|
50 |
-
],
|
51 |
-
"execution_count": null,
|
52 |
-
"outputs": []
|
53 |
-
},
|
54 |
-
{
|
55 |
-
"cell_type": "markdown",
|
56 |
-
"metadata": {
|
57 |
-
"id": "DKilCO-TU_s0"
|
58 |
-
},
|
59 |
-
"source": [
|
60 |
-
"# Import Model"
|
61 |
-
]
|
62 |
-
},
|
63 |
-
{
|
64 |
-
"cell_type": "code",
|
65 |
-
"metadata": {
|
66 |
-
"id": "VU33RjeOc8eG"
|
67 |
-
},
|
68 |
-
"source": [
|
69 |
-
"#import model class and tokenizer\n",
|
70 |
-
"from transformers import BlenderbotTokenizer, BlenderbotForConditionalGeneration"
|
71 |
-
],
|
72 |
-
"execution_count": null,
|
73 |
-
"outputs": []
|
74 |
-
},
|
75 |
-
{
|
76 |
-
"cell_type": "code",
|
77 |
-
"metadata": {
|
78 |
-
"id": "6LZEzJXpc8pg"
|
79 |
-
},
|
80 |
-
"source": [
|
81 |
-
"#download and setup the model and tokenizer\n",
|
82 |
-
"model_name = 'facebook/blenderbot-400M-distill'\n",
|
83 |
-
"tokenizer = BlenderbotTokenizer.from_pretrained(model_name)\n",
|
84 |
-
"model = BlenderbotForConditionalGeneration.from_pretrained(model_name)"
|
85 |
-
],
|
86 |
-
"execution_count": null,
|
87 |
-
"outputs": []
|
88 |
-
},
|
89 |
-
{
|
90 |
-
"cell_type": "markdown",
|
91 |
-
"metadata": {
|
92 |
-
"id": "_T9nRG5eVENY"
|
93 |
-
},
|
94 |
-
"source": [
|
95 |
-
"# make conversation"
|
96 |
-
]
|
97 |
-
},
|
98 |
-
{
|
99 |
-
"cell_type": "code",
|
100 |
-
"metadata": {
|
101 |
-
"id": "AkrWBF3af8Ns"
|
102 |
-
},
|
103 |
-
"source": [
|
104 |
-
"#making an utterance \n",
|
105 |
-
"utterance = \"My name is gold, I like football and coding\""
|
106 |
-
],
|
107 |
-
"execution_count": null,
|
108 |
-
"outputs": []
|
109 |
-
},
|
110 |
-
{
|
111 |
-
"cell_type": "code",
|
112 |
-
"metadata": {
|
113 |
-
"id": "JDDDJ2V3f8QT"
|
114 |
-
},
|
115 |
-
"source": [
|
116 |
-
"#tokenize the utterance\n",
|
117 |
-
"inputs = tokenizer(utterance, return_tensors=\"pt\")\n",
|
118 |
-
"inputs"
|
119 |
-
],
|
120 |
-
"execution_count": null,
|
121 |
-
"outputs": []
|
122 |
-
},
|
123 |
-
{
|
124 |
-
"cell_type": "code",
|
125 |
-
"metadata": {
|
126 |
-
"id": "-QYclYycf8TN"
|
127 |
-
},
|
128 |
-
"source": [
|
129 |
-
"#generate model results\n",
|
130 |
-
"result = model.generate(**inputs)\n",
|
131 |
-
"result"
|
132 |
-
],
|
133 |
-
"execution_count": null,
|
134 |
-
"outputs": []
|
135 |
-
},
|
136 |
-
{
|
137 |
-
"cell_type": "code",
|
138 |
-
"metadata": {
|
139 |
-
"id": "syB3F_iyf8Vt"
|
140 |
-
},
|
141 |
-
"source": [
|
142 |
-
"tokenizer.decode(result[0])"
|
143 |
-
],
|
144 |
-
"execution_count": null,
|
145 |
-
"outputs": []
|
146 |
-
}
|
147 |
-
]
|
148 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
blender_bot.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#import model class and tokenizer
|
2 |
+
from transformers import BlenderbotTokenizer, BlenderbotForConditionalGeneration
|
3 |
+
|
4 |
+
#import model class and tokenizer
|
5 |
+
from transformers import BlenderbotTokenizer, BlenderbotForConditionalGeneration
|
6 |
+
|
7 |
+
#download and setup the model and tokenizer
|
8 |
+
model_name = 'facebook/blenderbot-400M-distill'
|
9 |
+
tokenizer = BlenderbotTokenizer.from_pretrained(model_name)
|
10 |
+
model = BlenderbotForConditionalGeneration.from_pretrained(model_name)
|
11 |
+
|
12 |
+
def func (message):
|
13 |
+
inputs = tokenizer(message, return_tensors="pt")
|
14 |
+
result = model.generate(**inputs)
|
15 |
+
return tokenizer.decode(result[0])
|
16 |
+
|
17 |
+
import gradio as gr
|
18 |
+
app = gr.Interface(fn=func, inputs="textbox"inputs="textbox", outputs="textbox", title="Conversation Bot")
|
19 |
+
|
20 |
+
app.launch()
|