From 47e286ff632bd1de5c5d3267c5fa5dde9370ffec Mon Sep 17 00:00:00 2001 From: chriswebb09 Date: Thu, 12 Oct 2023 12:27:40 -0400 Subject: [PATCH] moved react logic from template files into their own .js files --- DirectReport/browserview/app.py | 86 +++++++++- DirectReport/browserview/static/js/account.js | 0 DirectReport/browserview/static/js/index.js | 55 +++++++ .../browserview/static/js/teamreport.js | 148 +++++++++++++++++ .../browserview/templates/_footer.html | 12 ++ .../browserview/templates/_navigation.html | 10 ++ .../browserview/templates/account.html | 4 +- DirectReport/browserview/templates/base.html | 29 +--- DirectReport/browserview/templates/index.html | 28 +--- .../browserview/templates/teamreport.html | 150 +----------------- 10 files changed, 316 insertions(+), 206 deletions(-) create mode 100644 DirectReport/browserview/static/js/account.js create mode 100644 DirectReport/browserview/static/js/teamreport.js create mode 100644 DirectReport/browserview/templates/_footer.html create mode 100644 DirectReport/browserview/templates/_navigation.html diff --git a/DirectReport/browserview/app.py b/DirectReport/browserview/app.py index 00f69071..d725fe9d 100644 --- a/DirectReport/browserview/app.py +++ b/DirectReport/browserview/app.py @@ -9,6 +9,29 @@ import openai import secrets import prompts +# +# from transformers import AutoModelForCausalLM +# from transformers import pipeline +# import torch +# from transformers import AutoModelForCausalLM, AutoTokenizer +# + +# def test(): +# access_token = "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" +# +# # torch.set_default_device('cuda') +# model = AutoModelForCausalLM.from_pretrained("microsoft/phi-1_5", trust_remote_code=True, torch_dtype="auto") +# tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-1_5", trust_remote_code=True, torch_dtype="auto") +# inputs = tokenizer('''```python +# def print_prime(n): +# """ +# Print all primes between 1 and n +# """''', return_tensors="pt", return_attention_mask=False) +# +# outputs = model.generate(**inputs, max_length=200) +# text = tokenizer.batch_decode(outputs)[0] +# print(text) + openai.api_key = secrets.SECRET_KEY @@ -20,6 +43,7 @@ def home(): Renders the homepage of the web application. :return: Rendered HTML template for the homepage. """ + #test() return render_template('index.html', title='Home') @app.errorhandler(404) @@ -47,13 +71,71 @@ def report(): prompt = "" if request.method == "POST": prompt = request.get_json()["prompt"] - print(prompt) + # print(prompt) + # elements = { + # "team": [ + # { + # "name": "AdrianPrantl", + # "accomplishments": "AdrianmadesignificantcontributionstotheDebugInfoandSILGen,includingaddingsupportfordebuginfoforcoroutineallocas,inlinedandspecializedgenericvariables.Healsoworkedonthemanglingtestcase,fixedsourcelocationsofvariableassignmentsandfunctioncalls,andaddedbuild-scriptsupportforSwiftLLDBbackwards-compatibilitytests.", + # "commits": "67" + # }, + # { + # "name": "AhmadAlhashemi", + # "accomplishments": "AhmadworkedontheParser,detectingnonbreakingspaceU+00A0andprovidingafix.Healsomademinorstyleeditsandaddedmorenon-breakingspacetestcases.", + # "commits": "5" + # }, + # { + # "name": "AkshayShrimali", + # "accomplishments": "AkshayupdatedtheREADME.mdfile.", + # "commits": "1" + # }, + # { + # "name": "AlanZeino", + # "accomplishments": "AlanfixedatypointhecodeexampleinlibSyntaxREADME.", + # "commits": "1" + # }, + # { + # "name": "Albin\"albinek\"Sadowski", + # "accomplishments": "AlbinfixedsyntaxhighlightinginCHANGELOG.", + # "commits": "1" + # }, + # { + # "name": "Alejandro", + # "accomplishments": "Alejandroremovedawarning,madesomedocumentationfixes,fixedBinaryFloatingPoint.random(in:)openrangereturningupperBound,andfixedaminorcodetypoinSILPro..Man..md.", + # "commits": "3" + # }, + # { + # "name": "AlexBlewitt", + # "accomplishments": "Alexworkedonseveralfixesincludingcompareforlhsandrhs,using||insteadof&&forkindcomparison,removingduplicateconditionalcheckandduplicateifstatement.", + # "commits": "5" + # } + # ], + # "report": { + # "summary": "Theteammadesignificantprogressthisweekwithatotalof83commits.ThemainfocuswasonDebugInfoandSILGenenhancements,Parserimprovements,andvariousfixes.", + # "highlights": [ + # { + # "title": "DebugInfoandSILGenEnhancements", + # "description": "AdrianPrantlmadesignificantcontributionstotheDebugInfoandSILGen,includingaddingsupportfordebuginfoforcoroutineallocas,inlinedandspecializedgenericvariables." + # }, + # { + # "title": "ParserImprovements", + # "description": "AhmadAlhashemiworkedontheParser,detectingnonbreakingspaceU+00A0andprovidingafix." + # }, + # { + # "title": "VariousFixes", + # "description": "Theteamworkedonseveralfixesincludingcompareforlhsandrhs,using||insteadof&&forkindcomparison,removingduplicateconditionalcheckandduplicateifstatement." + # } + # ], + # "conclusion": "Theteamdemonstratedgoodprogressthisweek,withafocusonenhancingDebugInfoandSILGen,improvingtheParser,andimplementingvariousfixes.Theteamshouldcontinuetofocusontheseareasinthecomingweek." + # } + # } + report = get_team_summarys_from_git_shortlog(prompt) elements = report.choices[0].message.content elements = elements.replace("'", '"') elements = elements.replace('"albinek"', '') json_object = json.loads(elements) - return json_object, 201 + return elements, 201 @app.route("/generate_email", methods=['POST']) def generate_email(): diff --git a/DirectReport/browserview/static/js/account.js b/DirectReport/browserview/static/js/account.js new file mode 100644 index 00000000..e69de29b diff --git a/DirectReport/browserview/static/js/index.js b/DirectReport/browserview/static/js/index.js index e69de29b..d2c7c5d8 100644 --- a/DirectReport/browserview/static/js/index.js +++ b/DirectReport/browserview/static/js/index.js @@ -0,0 +1,55 @@ +'use strict'; +const e = React.createElement; + +class Home extends React.Component { + render() { + return e( + 'div', + null, + React.createElement( + 'div', + { + className: "py-24 flex h-100", + style: {background: "linear-gradient(90deg, #667eea 0%, #764ba2 100%)"} + }, + React.createElement( + "div", + { + className: "container mx-auto px-6" + }, + React.createElement( + "h2", + { + className: "my-4 text-4xl font-bold mb-2 text-white" + }, + "DirectReport." + ), + React.createElement( + "h3", + { + className: "my-8 text-2xl mb-12 text-gray-200" + }, + "Keep track of your accomplishments each day of the workweek." + ), + React.createElement( + "div", + { + className: "my-8" + }, + React.createElement( + "a", + { + className: "my-12 px-14 py-5 text-lg font-bold text-center text-white bg-gray-400 rounded-full hover:bg-blue-800 shadow-lg uppercase", + href: "https://github.com/chriswebb09/DirectReport" + }, + "Github" + ) + ) + ) + ) + ); + } +} + +const domContainer = document.querySelector('#root'); +ReactDOM.render(e(Home), domContainer); diff --git a/DirectReport/browserview/static/js/teamreport.js b/DirectReport/browserview/static/js/teamreport.js new file mode 100644 index 00000000..53b2d6d1 --- /dev/null +++ b/DirectReport/browserview/static/js/teamreport.js @@ -0,0 +1,148 @@ +const { useState, useEffect } = React; + +const TeamData = () => { + const [teamData, setTeamData] = useState({}); + const [commentText, setCommentText] = useState("") + const [generatedEmail, setGeneratedEmail] = useState("") + const [isOpened, setIsOpened] = useState(false); + const [isHidden, setIsHidden] = useState(false); + + + const handleSubmit = e => { + e.preventDefault() + var dataForm = { + "prompt": commentText + }; + const formDataJsonString = JSON.stringify(dataForm); + fetch("/report", { + method: "POST", + headers: { + "Content-Type": "application/json", + "Accept": "application/json" + }, + body: formDataJsonString + }).then(function(res) { + return res.json(); + }).then(function(data) { + setTeamData(data); + toggle(); + }); + }; + + function toggle() { + setIsOpened(wasOpened => !wasOpened); + } + + function toggleHide() { + setIsHidden(wasHidden => !wasHidden); + } + + + const handleClick = e => { + e.preventDefault() + var dataForm = { + "prompt": JSON.stringify(teamData) + }; + const formDataJsonString = JSON.stringify(dataForm); + fetch("/generate_email", { + method: "POST", + headers: { + "Content-Type": "application/json", + "Accept": "application/json" + }, + body: formDataJsonString + }).then(function(res) { + return res.json(); + }).then(function(data) { + setGeneratedEmail(data["email"]); + toggleHide(); + }); + } + + return ( +
+

Generate Team Report From Metadata

+
+
+
+
+

Enter Github Data

+
+
+ +
+
+ +
+
+
+
+
+
+
+

Summary

+
+ {isOpened && ( +
+

+ { teamData["report"] !== undefined ? +

{teamData["report"]["summary"]}
+ : null + } +

+
+
    + {teamData["report"] && + teamData["report"]["highlights"].map(hightlight => +
  • +

    {hightlight.title}

    +

    {hightlight.description}

    +
  • + )} +
+
+
+ )} +
+
+
+
+
+

+ Team

+
+ {isOpened && ( +
+
+ {teamData["team"] && + teamData["team"].map(teammember => + + )} +
+
+ )} +
+
+
+
+

Generated Email

+ {isHidden && ( +
+ {generatedEmail} +
+ )} + {isOpened && ( +
+ +
+ )} +
+
+
+
+ + ); +}; + +const domContainer = document.querySelector('#root'); +ReactDOM.render(, domContainer); diff --git a/DirectReport/browserview/templates/_footer.html b/DirectReport/browserview/templates/_footer.html new file mode 100644 index 00000000..24cb870a --- /dev/null +++ b/DirectReport/browserview/templates/_footer.html @@ -0,0 +1,12 @@ + \ No newline at end of file diff --git a/DirectReport/browserview/templates/_navigation.html b/DirectReport/browserview/templates/_navigation.html new file mode 100644 index 00000000..df086663 --- /dev/null +++ b/DirectReport/browserview/templates/_navigation.html @@ -0,0 +1,10 @@ + \ No newline at end of file diff --git a/DirectReport/browserview/templates/account.html b/DirectReport/browserview/templates/account.html index c7ef9efc..f3d2a0f9 100644 --- a/DirectReport/browserview/templates/account.html +++ b/DirectReport/browserview/templates/account.html @@ -42,8 +42,8 @@

Account

); }; - const root = ReactDOM.createRoot(document.getElementById("root")); - root.render(); + const domContainer = document.querySelector('#root'); + ReactDOM.render(, domContainer); {% endblock %} \ No newline at end of file diff --git a/DirectReport/browserview/templates/base.html b/DirectReport/browserview/templates/base.html index 698f0df5..1596afea 100644 --- a/DirectReport/browserview/templates/base.html +++ b/DirectReport/browserview/templates/base.html @@ -14,37 +14,12 @@ -
- + {% include "_navigation.html" %}
- - {% block content %} {% endblock %} - - - +{% include "_footer.html" %} diff --git a/DirectReport/browserview/templates/index.html b/DirectReport/browserview/templates/index.html index bd6e5b2a..5327c001 100644 --- a/DirectReport/browserview/templates/index.html +++ b/DirectReport/browserview/templates/index.html @@ -5,33 +5,7 @@ {% block content %}
- +
{% endblock %} \ No newline at end of file diff --git a/DirectReport/browserview/templates/teamreport.html b/DirectReport/browserview/templates/teamreport.html index 6f2ba40d..b9ba513d 100644 --- a/DirectReport/browserview/templates/teamreport.html +++ b/DirectReport/browserview/templates/teamreport.html @@ -6,153 +6,7 @@ {% block content %}
-
- - - +
+
{% endblock %} \ No newline at end of file