33 lines
728 B
Python
33 lines
728 B
Python
|
#!/usr/bin/env python3
|
||
|
|
||
|
# Not written by retoor! This is generated boiler plate to give an example!
|
||
|
|
||
|
import cgi
|
||
|
import cgitb
|
||
|
from xmlrpc.client import ServerProxy
|
||
|
client = ServerProxy("https://api.molodetz.nl/rpc")
|
||
|
ask_gpt = client.gpt4o_mini
|
||
|
|
||
|
cgitb.enable()
|
||
|
|
||
|
print("Content-Type: text/html")
|
||
|
print()
|
||
|
|
||
|
import pathlib
|
||
|
|
||
|
|
||
|
form = cgi.FieldStorage()
|
||
|
question = form.getvalue("question", "")
|
||
|
|
||
|
page_source = pathlib.Path(__file__).parent.joinpath("gpt_template.html").read_text()
|
||
|
|
||
|
if question:
|
||
|
try:
|
||
|
response = ask_gpt(question)
|
||
|
except Exception as e:
|
||
|
response = f"Error: {e}"
|
||
|
page_source = page_source.replace("...", response)
|
||
|
page_source = page_source.replace("display:none;","")
|
||
|
|
||
|
print(page_source)
|