Skip to content

Commit

Permalink
Major update from SummarizeMe.io Production Code
Browse files Browse the repository at this point in the history
  • Loading branch information
satishsurath committed Feb 22, 2024
1 parent d2281b4 commit b5250e5
Show file tree
Hide file tree
Showing 13 changed files with 1,497 additions and 280 deletions.
58 changes: 56 additions & 2 deletions app/db_file_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ def get_summary_from_hash(text2summarize_hash):
else:
return False

# function to return the Summary if the hash of text2summarize is already in the database
def get_key_insights_from_hash(text2summarize_hash):
entry = Entry_Post.query.filter_by(text2summarize_hash=text2summarize_hash).first()
if entry:
if entry.openAIkeyInsights == None:
return False
else:
return entry.openAIkeyInsights
else:
return False


# function to return the Page Title if the hash of text2summarize is already in the database
def get_title_from_hash(text2summarize_hash):
Expand All @@ -158,7 +169,14 @@ def get_title_from_hash(text2summarize_hash):
# Function to write to the database
def write_entry_to_db(posttype, url, text2summarizedb, openAIsummarydb, openAItitledb):
try:
if not session.get('content_written', False):
# Check for an existing entry with the same openAIkeyInsights
existing_entry = Entry_Post.query.filter_by(openAIsummary=openAIsummarydb).first()

if existing_entry and not session.get('content_written', False):
# Update the openAIkeyInsights for the existing entry
existing_entry.openAIkeyInsights = openAIsummarydb
db.session.commit()
elif not session.get('content_written', False):
text2summarize_hash = hashlib.sha256(text2summarizedb.encode('utf-8')).hexdigest()
entry = Entry_Post(posttype=posttype, url=url, text2summarize=text2summarizedb, openAIsummary=openAIsummarydb, text2summarize_hash=text2summarize_hash, openAItitle=openAItitledb)
db.session.add(entry)
Expand All @@ -170,7 +188,43 @@ def write_entry_to_db(posttype, url, text2summarizedb, openAIsummarydb, openAIti
user = oAuthUser.query.filter_by(linkedin_id=user_linkedin).first()
if user:
# User exists, write to entry_history table
#entry_history = Entry_Posts_History(oAuthUser_id=user.id, entry_id=entry.id)
entry_history = Entry_Posts_History(oAuthUser_id=user.id, entry_post_id=entry.id)
db.session.add(entry_history)
db.session.commit()

session['content_written'] = True
return True
except Exception as e: # Catch the exception
db.session.rollback() # Rollback the session
print("Error occurred. Could not write to database.")
print(f"Error details: {e}") # Print the details of the error
app.logger.error("Error occurred. Could not write to database.")
app.logger.error(f"Error details: {e}") # Log the details of the error
return False
finally:
db.session.close()

# Function to write to the database
def write_insights_to_db(posttype, url, text2summarizedb, openAIkeyInsightsdb, openAItitledb):
try:
text2summarize_hash = hashlib.sha256(text2summarizedb.encode('utf-8')).hexdigest()
existing_entry = Entry_Post.query.filter_by(text2summarize_hash=text2summarize_hash).first()

if existing_entry and not session.get('content_written', False):
# Update the openAIkeyInsights for the existing entry
existing_entry.openAIkeyInsights = openAIkeyInsightsdb
db.session.commit()
elif not session.get('content_written', False):
entry = Entry_Post(posttype=posttype, url=url, text2summarize=text2summarizedb, openAIkeyInsights=openAIkeyInsightsdb, text2summarize_hash=text2summarize_hash, openAItitle=openAItitledb)
db.session.add(entry)
db.session.commit()

# Check if user is logged in
if session.get('linkedin_id', False):
user_linkedin = session['linkedin_id']
user = oAuthUser.query.filter_by(linkedin_id=user_linkedin).first()
if user:
# User exists, write to entry_history table
entry_history = Entry_Posts_History(oAuthUser_id=user.id, entry_post_id=entry.id)
db.session.add(entry_history)
db.session.commit()
Expand Down
1,132 changes: 1,007 additions & 125 deletions app/routes.py

Large diffs are not rendered by default.

64 changes: 49 additions & 15 deletions app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@
}

input:checked + .slider {
background-color: #2196F3;
}

input:focus + .slider {
box-shadow: 0 0 1px #2196F3;
}
background-color: var(--form-bkg-color);
}
input:focus + .slider {
box-shadow: 0 0 1px var(--form-bkg-color);
}

input:checked + .slider:before {
-webkit-transform: translateX(13px); /* 50% of the original translateX value */
Expand Down Expand Up @@ -168,6 +168,16 @@
alert('Summary copied to clipboard!');
}

function copyOriginalContentToClipboard() {
const textarea = document.createElement('textarea');
textarea.textContent = document.querySelector('#original-content').textContent;
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
alert('Original Content Text copied to clipboard!');
}


function setTheme(theme) {
const root = document.documentElement;
Expand Down Expand Up @@ -218,10 +228,22 @@
<nav class="navbar">
<ul>
<li> <a href="{{ url_for('index') }}"><img src="/static/SummarizeMe_transparent_logov4.png" alt="SummarizeMe.io Logo - AI-Powered Text Summarization" aria-label="SummarizeMe.io Homepage" height="45px" width="162px"></a></li>
<li class="nav-links"> Summarize: <ul>
<li class="nav-links"> <a href="{{ url_for('summarizeText') }}" alt="SummarizeMe.io - Text Summarization" aria-label="SummarizeMe.io - Text Summarization">Text</a></li>
<li class="nav-links"> <a href="{{ url_for('summarizeURL') }}" alt="SummarizeMe.io - Webpage Summarization" aria-label="SummarizeMe.io - Webpage Summarization">URL</a></li>
<li class="nav-links"> <a href="{{ url_for('summarizeYouTube') }}" alt="SummarizeMe.io - YouTube Summarization" aria-label="SummarizeMe.io - YouTube Summarization">YouTube</a></li>
<li class="nav-links"> <a href="{{ url_for('summarizePDF') }}" alt="SummarizeMe.io - PDF Summarization" aria-label="SummarizeMe.io - PDF Summarization">PDF</a></li>
</ul>
</li>
{% if current_user.is_authenticated %}
<li class="nav-links"> <span style="color:red;">New:</span> Key Insights: <ul>
<li class="nav-links"> <a href="{{ url_for('keyInsightsText') }}" alt="SummarizeMe.io - Text Key Insights" aria-label="SummarizeMe.io - Text Key Insights">Text</a></li>
<li class="nav-links"> <a href="{{ url_for('keyInsightsURL') }}" alt="SummarizeMe.io - Webpage Key Insights" aria-label="SummarizeMe.io - Webpage Key Insights">URL</a></li>
<li class="nav-links"> <a href="{{ url_for('keyInsightsYouTube') }}" alt="SummarizeMe.io - YouTube Key Insights" aria-label="SummarizeMe.io - YouTube Key Insights">YouTube</a></li>
<li class="nav-links"> <a href="{{ url_for('keyInsightsPDF') }}" alt="SummarizeMe.io - PDF Key Insights" aria-label="SummarizeMe.io - PDF Key Insights">PDF</a></li>
</ul>
</li>
{% endif %}
<li class="nav-links"> <a href="{{ url_for('logs') }}">Logs</a></li>
{% if current_user.is_authenticated %}
<li class="nav-links"> <a href="{{ url_for('openAI_debug') }}">OpenAI Debug</a></li>
Expand All @@ -231,15 +253,16 @@
<div class="toggle-container">
<div class="toggle-dark-mode-animation">
<!-- Add the toggle switch element -->
Dark Mode
<label class="switch">
<input type="checkbox" id="toggle-theme" onclick="setTheme()" aria-label="toggle-dark-mode-theme">
<span class="slider round"></span>
</label>
</div>
</div>
</li>
<li class="nav-links"> <a href="https://plus-beta.summarizeme.io" alt="SummarizeMe.io(Plus)" aria-label="SummarizeMe.io(Plus)"><span style="color:red;">New:</span> SummarizeMe.io<span style="color:red;font-size:2em;">+</span></a></li>
<!--
<li class="nav-links"> <a href="https://plus-beta.summarizeme.io" alt="SummarizeMe.io(Plus)" aria-label="SummarizeMe.io(Plus)"><span style="color:red;">New:</span> SummarizeMe.io<span style="color:red;font-size:2em;">+</span></a></li>
-->
</ul>
</nav>

Expand All @@ -248,10 +271,21 @@
{% block content %}

{% endblock %}
<hr>

</div>
<div style="color: #f44336; text-align: center;">
<script async
src="https://js.stripe.com/v3/buy-button.js">
</script>
<stripe-buy-button
buy-button-id="buy_btn_1MzQKTF7JYWyImGptMK4aBpD"
publishable-key="pk_live_51MzPQPF7JYWyImGpBNyi9ct40hTB3kq0m6ffByr5VbqYqYxScIE0ijMwVJowRfX6tHqsDFJlyoGYThBoGsZl1u9n00a4qDP0xO">
</stripe-buy-button>
</div>
<div class="item-footer">



<div class="item-footer">
<ul>
<li class="nav-links">
<a href="https://github.com/satishsurath/summarizeme.io" target="_blank" aria-label="Contribute to SummarizeMe.io Open Source Code on Github">
Expand All @@ -260,9 +294,9 @@
<path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/>
</svg>
</a>
</li>
<li>&nbsp</li>
<li>&nbsp</li>
</li class="nav-links">
<li class="nav-links">&nbsp</li>
<li class="nav-links">&nbsp</li>
<li class="nav-links">
<a href="https://twitter.com/summarizemeio" target="_blank" aria-label="Follow SummarizeMe.io on Twitter">

Expand All @@ -271,8 +305,8 @@
</svg>
</a>
</li>
<li>&nbsp</li>
<li>&nbsp</li>
<li class="nav-links">&nbsp</li>
<li class="nav-links">&nbsp</li>
<li class="nav-links">
<a href="https://www.linkedin.com/company/summarizeme/" aria-label="Follow SummarizeMe.io on Linkedin" target="_blank">

Expand Down
Loading

0 comments on commit b5250e5

Please sign in to comment.