gospacedev commited on
Commit
cc1dbdd
1 Parent(s): 857499b

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +47 -0
  2. index.html +71 -18
  3. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request
2
+ from transformers import BlenderbotTokenizer, BlenderbotForConditionalGeneration
3
+
4
+ # Load the Blenderbot-400M-distill model
5
+ mname = "facebook/blenderbot-400M-distill"
6
+ model = BlenderbotForConditionalGeneration.from_pretrained(mname)
7
+ tokenizer = BlenderbotTokenizer.from_pretrained(mname)
8
+
9
+ app = Flask(__name__)
10
+
11
+ # Create an empty tuple to store the user_input data
12
+ history = ("")
13
+ ui_history = []
14
+
15
+ # Create a function to generate a response to a user"s input
16
+ def generate_response(history):
17
+ # Encode the user"s input
18
+ inputs = tokenizer(history, return_tensors="pt")
19
+
20
+ # Generate a response
21
+ reply_ids = model.generate(**inputs, max_length=60)
22
+
23
+ # Decode the response
24
+ return tokenizer.batch_decode(reply_ids, skip_special_tokens=True)[0]
25
+
26
+
27
+ @app.route("/", methods=["GET", "POST"])
28
+ def index():
29
+ if request.method == "POST":
30
+ global history
31
+
32
+ user_input = request.form["user_input"]
33
+ history += tokenizer.bos_token + user_input + tokenizer.eos_token + " "
34
+
35
+ response = generate_response(history)
36
+ history += tokenizer.bos_token + response + tokenizer.eos_token + " "
37
+
38
+ ui_history.append(user_input)
39
+ ui_history.append(response)
40
+ else:
41
+ user_input = ""
42
+ response = ""
43
+
44
+ return render_template("index.html", ui_history=ui_history)
45
+
46
+ if __name__ == "__main__":
47
+ app.run("0.0.0.0", port=80)
index.html CHANGED
@@ -1,19 +1,72 @@
1
  <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <!DOCTYPE html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>Blenderbot</title>
8
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
9
+ </head>
10
+ <style>
11
+ body {
12
+ font-family: Arial, Helvetica, sans-serif;
13
+ background-color: rgb(59, 59, 59);
14
+ color: white;
15
+ }
16
+
17
+ input {
18
+ color: white;
19
+ font-size: large;
20
+ }
21
+
22
+ ul {
23
+ list-style-type: none;
24
+ }
25
+
26
+ li {
27
+ color: white;
28
+ }
29
+
30
+ li:nth-child(even) {
31
+ color:rgb(0, 200, 200);
32
+ }
33
+
34
+ #title {
35
+ font-size: large;
36
+ margin-top: 5%;
37
+ margin-left: 17%;
38
+ margin-right: 17%;
39
+ margin-bottom: 2%;
40
+ }
41
+
42
+ #chat {
43
+ font-size: large;
44
+ margin-top: 5%;
45
+ margin-left: 17%;
46
+ margin-right: 17%;
47
+ margin-bottom: 7%;
48
+ }
49
+ </style>
50
+
51
+ <body>
52
+ <div id="title">
53
+ <h1>Blenderbot🚀🚀🚀</h1>
54
+ </div>
55
+
56
+
57
+ <div id="chat">
58
+ <ul>
59
+ {% for item in ui_history %}
60
+ <li>{{ item }}</li>
61
+ {% endfor %}
62
+ </ul>
63
+
64
+ <form action="/" id="chat-form" method="post" class="input-field">
65
+ <input type="text" name="user_input" placeholder="Enter your response">
66
+ <button type="submit" class="btn">Send</button>
67
+ </form>
68
+ </div>
69
+
70
+ </body>
71
+
72
+ </html>
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ Flask==2.3.2
2
+ transformers==4.30.1
3
+ torch==2.0.*