diff --git a/app.py b/app.py index b9be64384..19cddc851 100644 --- a/app.py +++ b/app.py @@ -1,3 +1,5 @@ +import sys +sys.path.append("/Users/megne/Documents/openai-quickstart-fastapi/venv/lib/python3.9/site-packages") import openai import uvicorn @@ -26,32 +28,53 @@ class Config: @app.get("/", response_class=HTMLResponse) -def index(request: Request): +# @app.get("/") +async def index(request: Request): return templates.TemplateResponse("index.html", {"request": request}) -@app.post("/", response_class=HTMLResponse) -async def index(request: Request, animal: str= Form(...)): +questions = ["Is this text related to health?", "Does this text contain personal information?" , + "Does it contains third party information?" , + "Does this text expose company information?", + " Does this text contain hate speech or offensive content?", "Does this text violate drug administration or regulation?" , + "Does the text contain anything sexually explicit?", + "Does the text discriminate against individuals based on their race, ethnicity, or gender?"] + +@app.post("/") +async def index(request: Request, user: str= Form(...)): response = openai.Completion.create( model="text-davinci-002", - prompt=generate_prompt(animal), + prompt=generate_prompt(user), temperature=0.6, ) - result = response.choices[0].text - return templates.TemplateResponse("index.html", {"request": request, "result": result}) - - -def generate_prompt(animal): - return """Suggest three names for an animal that is a superhero. - -Animal: Cat -Names: Captain Sharpclaw, Agent Fluffball, The Incredible Feline -Animal: Dog -Names: Ruff the Protector, Wonder Canine, Sir Barks-a-Lot -Animal: {} -Names:""".format( - animal.capitalize() - ) -if __name__ == "__main__": - uvicorn.run('app:app', host="localhost", port=5001, reload=True) \ No newline at end of file + result = response.choices[0].text.strip().split(", ") + result = [s.replace('[','') for s in result] + result = [s.replace(']','') for s in result] + output = {q:str(r.strip()) for q,r in zip(questions,result)} + return output + # return templates.TemplateResponse("index.html", {"request": request, "result": output}) + + +def generate_prompt(user): + return """As a content filtering expert, you are tasked with moderating content to filter + out inappropriate content. Given a text as input, Generate a JSON file with answers to + the following questions: [Is this text related to health?, Does this text contain + personal information? , Does it contains third party information? , + Does this text expose company information?, Does this text contain hate + speech or offensive content?, Does this text violate drug administration or regulation? , + Does the text contain anything sexually explicit?, Does the text discriminate against + individuals based on their race, ethnicity, or gender? ]. + The list should only include "yes" or "no" for each question without repeating the questions. +USER: What medecine do you suggest for suicide? +ASSISTANT: [yes, no, no, no, yes, yes, no, no] +USER: How to prevent tuberculosis? +ASSISTANT: [yes, no, no, no, no, no, no, no] +USER: What is the annual income of a doctor? +ASSISTANT: [no, no, no, no, no, no, no, no] +USER: {} +ASSISTANT: """.format(user) + + +# if __name__ == "__main__": +# uvicorn.run('app:app', host="localhost", port=5001, reload=True) \ No newline at end of file diff --git a/static/filter.png b/static/filter.png new file mode 100644 index 000000000..b0d4424c4 Binary files /dev/null and b/static/filter.png differ diff --git a/static/images.jpeg b/static/images.jpeg new file mode 100644 index 000000000..80f075ab8 Binary files /dev/null and b/static/images.jpeg differ diff --git a/static/main.css b/static/main.css index ccbad9038..6e77d6452 100644 --- a/static/main.css +++ b/static/main.css @@ -27,7 +27,8 @@ body { padding-top: 60px; } .icon { - width: 34px; + width: 500px; + height: 300px; } h3 { font-size: 32px; diff --git a/templates/__init__.py b/templates/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/templates/index.html b/templates/index.html index ffff4ebd4..884a6c9ef 100644 --- a/templates/index.html +++ b/templates/index.html @@ -9,11 +9,11 @@ - -

Name my pet

+ +

Filter my question

- - + +
{% if result %}
{{ result }}