hat geklappt habe nur noch eine frage: wo finde ich jetzt meine webseite?
from google.colab.output import eval_js
from http.server import BaseHTTPRequestHandler, HTTPServer
import urllib.parse
import json
port = 8000
colab_url = eval_js(f'google.colab.kernel.proxyPort({port})')
html_code = '''
<!doctype html>
<html lang="de">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="
https://fonts.googleapis.com/css?family=Lato">
<link rel="stylesheet" href="
https://stackpath.bootstrapcdn.com/boot ... ap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<style>
html, body { font-family: 'Lato', sans-serif; }
.main-container { height: 100%; display: flex; flex-direction: column; }
.cover-container { height: 100vh; }
textarea { box-sizing: border-box; height: 100%; margin-top: 6px; margin-bottom: 6px; }
button { box-sizing: border-box; }
footer { margin-top: 12px; }
</style>
<script>
function init() {
const t = document.getElementById("textarea");
t.setSelectionRange(t.value.length, t.value.length); // move cursor to end
t.addEventListener('keydown', function(e) {
if(e.keyCode === 9) { // tab was pressed
autoComplete();
e.preventDefault(); // prevent tab navigation
}
},false);
}
function autoComplete() {
const t = document.getElementById("textarea");
const [start, end] = [t.selectionStart, t.selectionEnd];
const prefixText = t.value.substring(0, t.selectionStart);
fetch('/autocomplete', { method: 'POST', body: JSON.stringify(prefixText) }).
then(response => response.json()).
then(function(newText) {
textarea.focus();
textarea.setRangeText(newText, start, end, 'select');
});
}
</script>
<title>GPT-2 Text-Autopilot</title>
</head>
<body onload="init()">
<div class="container-fluid cover-container d-flex flex-column">
<div class="row flex-fill">
<div class="col-12">
<main class="main-container">
<h1>🦄 GPT-2 Schreib-Autopilot</h1>
<div>Schreibblockade? Müde? Nutze den Schreib-Autopiloten, und Deine Texte schreiben sich von selbst! 🤩</div>
<textarea id="textarea" autofocus="on" autocomplete="off" lang="de">Er dachte, automatisches Schreiben wäre eine gute Idee weil</textarea>
<button type="button" class="btn btn-primary" onclick="autoComplete()">automatisch vervollständigen (Tab)</button>
</main>
</div>
</div>
<footer>© Copyright 2020 Oliver Flasch</footer>
</div>
</body>
</html>
'''
class WebServiceHandler(BaseHTTPRequestHandler):
def do_GET(self):
parsed_url = urllib.parse.urlparse(self.path)
if parsed_url.path == '/':
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write(html_code.encode('utf-8'))
else:
self.send_response(404)
self.end_headers()
def do_POST(self):
parsed_url = urllib.parse.urlparse(self.path)
if parsed_url.path == '/autocomplete':
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
content_length = int(self.headers['Content-Length'])
prefix_text = json.loads(self.rfile.read(content_length))
generated_text = gpt2_gen(mw, prefix_text, n_tokens_to_generate=5, top_k=8)
new_text = generated_text[len(prefix_text):]
self.wfile.write(json.dumps(new_text).encode('utf-8'))
else:
self.send_response(404)
self.end_headers()