This is neither valid HTML nor valid Python. You can't simply mix in HTML tags into the middle of a Python script like that: you need at the very least to put them inside quotes so that they are a valid string.
#!/usr/bin/python
print "Content-Type: text/html\n"
print """
<!DOCTYPE html>
<html>
<pre>
"""
def ...
print facegenerator()
print """</pre>
</html>"""