Skip to content

Commit

Permalink
moved react logic from template files into their own .js files
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswebb09 committed Oct 12, 2023
1 parent a58ae16 commit 47e286f
Show file tree
Hide file tree
Showing 10 changed files with 316 additions and 206 deletions.
86 changes: 84 additions & 2 deletions DirectReport/browserview/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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():
Expand Down
Empty file.
55 changes: 55 additions & 0 deletions DirectReport/browserview/static/js/index.js
Original file line number Diff line number Diff line change
@@ -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);
148 changes: 148 additions & 0 deletions DirectReport/browserview/static/js/teamreport.js
Original file line number Diff line number Diff line change
@@ -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 (
<div>
<h1 class="self-center text-center text-4xl text-indigo-800 tracking-wide text-center font-black mb-14 mx-20 px-20">Generate Team Report From Metadata</h1>
<div class="grid grid-cols-3 gap-10 mt-10 mb-20 mx-20">
<div class="col-span-1 justify-center my-10" id="edit_summary_div">
<div class="shadow-lg py-1 border-4 border-indigo-600 rounded-2xl px-30 mb-10">
<form class=" py-2 px-2" onSubmit={handleSubmit}>
<h1 class="self-center text-center text-indigo-700 tracking-wide text-2xl text-center font-bold mb-4 mt-6">Enter Github Data</h1>
<div class="self-center mb-6 mt-5">
<div class="py-4 px-10 mx-0 min-w-full flex flex-col items-center">
<textarea id="prompt_input" cols="40" rows="13" class="self-center border-4 border-indigo-700 w-90 sm:w-90 text-base tracking-wide text-indigo-700 placeholder-white border rounded-2xl focus:shadow-outline" value={commentText} onChange={e => setCommentText(e.target.value)} ></textarea>
</div>
<div class="px-10 mx-0 min-w-full flex flex-col items-center">
<button id="submit_prompt_btn" class="shadow-md w-80 sm:w-90 tracking-wide bg-white hover:bg-indigo-700 text-indigo-700 hover:text-white border-4 border-indigo-700 hover:border-gray-200 text-xl font-semibold py-4 px-10 rounded-lg mt-10" type="submit">Generate</button>
</div>
</div>
</form>
</div>
</div>
<div id="show_summmary_div" class="col-span-1 justify-center my-10">
<div class="shadow-lg border-4 border-indigo-700 rounded-2xl px-30 mb-10">
<h1 class="self-center text-center text-2xl tracking-wide text-indigo-700 text-center font-bold mb-10 mt-10 mx-20 px-20">Summary</h1>
<div id="summary" class="px-5 mx-0 mb-9 mt-9">
{isOpened && (
<div id="summary-container" class="bg-white ml-10 mr-10 overflow-y-scroll h-90 rounded-2xl border-4 border-indigo-700 tracking-wide text-gray-500 md:text-gl dark:text-gray-400 mt-8 mb-14 px-1 py-4">
<p id="show_summary" class="w-90 sm:w-90 overflow-y-auto break-words">
{ teamData["report"] !== undefined ?
<div className="my-7 px-5 text-lg tracking-wide text-indigo-700">{teamData["report"]["summary"]}</div>
: null
}
</p>
<div class="h-80">
<ul className="px-5">
{teamData["report"] &&
teamData["report"]["highlights"].map(hightlight =>
<li className="mb-3">
<h3 className="font-bold text-lg mb-1 tracking-wide text-indigo-700">{hightlight.title}</h3>
<p class="w-90 sm:w-90 overflow-y-auto text-lg font-md break-words tracking-wide text-indigo-700">{hightlight.description}</p>
</li>
)}
</ul>
</div>
</div>
)}
</div>
</div>
</div>
<div id="team_member_to_select" class="col-span-1 justify-center my-10">
<div class="shadow-lg py-1 border-4 border-indigo-700 rounded-2xl px-9 mb-9">
<h1 class="self-center text-center text-2xl tracking-wide text-indigo-700 text-center font-bold mb-6 mt-8 mx-20 px-20">
Team</h1>
<div id="display_team" class="mb-6 my-9"></div>
{isOpened && (
<div className="content-center py-2 h-90 rounded-2xl ml-6 mb-12 border-4 border-indigo-700 mx-5 px-3">
<div class="items-center my-6 mx-2 px-4 select-none">
{teamData["team"] &&
teamData["team"].map(teammember =>
<button className="py-1 px-4 pb-2 pt-2.5 mr-3 my-2 shadow-md no-underline rounded-full text-indigo-700 font-sans border-4 font-bold text-sm border-indigo-700 btn-primary hover:text-white hover:bg-indigo-700 focus:outline-none active:shadow-none">{teammember.name}</button>
)}
</div>
</div>
)}
</div>
</div>
<div class="col-span-3 my-12 ml-10 mr-10 mb-10 mt-40">
<div class="shadow-lg py-3 border-4 border-indigo-700 rounded-2xl px-30">
<h1 class="self-center text-center text-2xl text-indigo-700 tracking-wide font-bold w-100 mb-10 mt-10">Generated Email</h1>
{isHidden && (
<div id ="text-content" class="bg-white ml-20 mr-20 rounded-2xl py-20 tracking-wide text-gray-500 md:text-md dark:text-gray-400 px-20 mx-20 my-10">
{generatedEmail}
</div>
)}
{isOpened && (
<div class="py-10 px-10 min-w-full flex flex-col items-center">
<button type="button" id="generate_email_btn" class="shadow-md w-80 sm:w-90 bg-white hover:bg-black border-4 border-indigo-700 text-indigo-700 text-xl font-semibold py-4 px-10 rounded-lg" onClick={handleClick}>Generate Email</button>
</div>
)}
</div>
</div>
</div>
</div>

);
};

const domContainer = document.querySelector('#root');
ReactDOM.render(<TeamData />, domContainer);
12 changes: 12 additions & 0 deletions DirectReport/browserview/templates/_footer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<footer class="bottom-0 bg-white rounded-lg shadow m-4 dark:bg-gray-800">
<div class="w-full mx-auto max-w-screen-xl p-4 md:flex md:items-center md:justify-between">
<span class="text-sm text-gray-500 sm:text-center dark:text-gray-400">© 2023 <a href="/" class="hover:underline">DirectReport.™</a>. All Rights Reserved.
</span>
<ul class="flex flex-wrap items-center mt-3 text-sm font-medium text-gray-500 dark:text-gray-400 sm:mt-0">
<li><a href="#" class="mr-4 hover:underline md:mr-6 ">About</a></li>
<li><a href="#" class="mr-4 hover:underline md:mr-6">Privacy Policy</a></li>
<li><a href="#" class="mr-4 hover:underline md:mr-6">Licensing</a></li>
<li><a href="#" class="hover:underline">Contact</a></li>
</ul>
</div>
</footer>
10 changes: 10 additions & 0 deletions DirectReport/browserview/templates/_navigation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<nav class="bg-gray-900 text-white w-screen">
<div class="px-14 py-6 flex w-full items-center">
<a class="ml-14 w-3/4 text-2xl font-bold" href="/">DirectReport.</a>
<ul class="flex px-6 font-semibold font-heading space-x-18">
<li><a class="px-6 text-xl hover:text-gray-200" href="/teamreport">Reports</a></li>
<li><a class="px-6 text-xl hover:text-gray-200" href="https://chriswebb09.github.io/DirectReport/">Docs</a></li>
<li><a class="px-6 text-xl hover:text-gray-200" href="/account">Account</a></li>
</ul>
</div>
</nav>
4 changes: 2 additions & 2 deletions DirectReport/browserview/templates/account.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ <h1 class="text-center py-10 bg-blue-50">Account</h1>
</div>
);
};
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(<Account />);
const domContainer = document.querySelector('#root');
ReactDOM.render(<Account />, domContainer);
</script>
</main>
{% endblock %}
29 changes: 2 additions & 27 deletions DirectReport/browserview/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,12 @@
<script src="https://cdn.tailwindcss.com?plugins=forms,typography,aspect-ratio,line-clamp"></script>
<link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='css/main.css') }}">
</head>

<header class="sticky top-0 z-50">
<nav class="bg-gray-900 text-white w-screen">
<div class="px-14 py-6 flex w-full items-center">
<a class="ml-14 w-3/4 text-2xl font-bold" href="/">DirectReport.</a>
<ul class="flex px-6 font-semibold font-heading space-x-18">
<li><a class="px-6 text-xl hover:text-gray-200" href="/teamreport">Reports</a></li>
<li><a class="px-6 text-xl hover:text-gray-200" href="https://chriswebb09.github.io/DirectReport/">Docs</a></li>
<li><a class="px-6 text-xl hover:text-gray-200" href="/account">Account</a></li>
</ul>
</div>
</nav>
{% include "_navigation.html" %}
</header>

<body>

{% block content %}
{% endblock %}

</body>

<footer class="bottom-0 bg-white rounded-lg shadow m-4 dark:bg-gray-800">
<div class="w-full mx-auto max-w-screen-xl p-4 md:flex md:items-center md:justify-between">
<span class="text-sm text-gray-500 sm:text-center dark:text-gray-400">© 2023 <a href="/" class="hover:underline">DirectReport.™</a>. All Rights Reserved.
</span>
<ul class="flex flex-wrap items-center mt-3 text-sm font-medium text-gray-500 dark:text-gray-400 sm:mt-0">
<li><a href="#" class="mr-4 hover:underline md:mr-6 ">About</a></li>
<li><a href="#" class="mr-4 hover:underline md:mr-6">Privacy Policy</a></li>
<li><a href="#" class="mr-4 hover:underline md:mr-6">Licensing</a></li>
<li><a href="#" class="hover:underline">Contact</a></li>
</ul>
</div>
</footer>
{% include "_footer.html" %}
</html>
Loading

0 comments on commit 47e286f

Please sign in to comment.