Skip to content

Commit

Permalink
Merge branch 'main' into add/discussionForum
Browse files Browse the repository at this point in the history
  • Loading branch information
Sawan-Kushwah authored Nov 8, 2024
2 parents 0215b18 + 229e493 commit c29da5e
Show file tree
Hide file tree
Showing 7 changed files with 383 additions and 115 deletions.
17 changes: 17 additions & 0 deletions SignIn_SignUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,20 @@ function closeForm(formType) {
document.getElementById("signupForm").style.display = "none";
}
}

function checkLogin() {
const isLoggedIn = localStorage.getItem('authToken'); // Example: Check for token
const profileLink = document.getElementById('profileLink');

// Show "My Profile" if the user is logged in
if (isLoggedIn) {
profileLink.style.display = 'block';
}
}

// Toggle menu display
function toggleProfileMenu() {
const profileMenu = document.getElementById('profileMenu');
profileMenu.style.display = profileMenu.style.display === 'block' ? 'none' : 'block';
}

75 changes: 75 additions & 0 deletions backend/generateFromAi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from flask import Flask, request, jsonify
from flask_cors import CORS
import google.generativeai as palm
import os
from dotenv import load_dotenv

app = Flask(__name__)
CORS(app) # Enable CORS for all routes

# Load API key from .env file
load_dotenv()
palm_api_key = os.getenv('PALM_API_KEY') # Get your API key from environment variable
if not palm_api_key:
raise ValueError("API key is missing. Please set your API key in the environment variables.")
palm.configure(api_key=palm_api_key)

@app.route('/generate_trending_titles', methods=['GET'])
def generate_trending_titles():
try:
prompt = """
You are a content generator specialized in creating catchy and engaging blog titles.
Please generate 20 trending blog titles that would appeal to a broad audience in the current time.
The titles should be innovative, popular, and attention-grabbing.
"""
model = palm.GenerativeModel('gemini-pro')
response = model.generate_content(prompt)
blog_titles = response.text.strip().split("\n")
return jsonify({"trending_titles": blog_titles[:10]}), 200
except Exception as e:
print("Error:", str(e))
return jsonify({"error": "An error occurred while generating the blog titles."}), 500

# New endpoint to generate content based on the title
@app.route('/generate-content', methods=['POST'])
def generate_content():
try:
# Get the title and summary from the request
data = request.get_json()
title = data.get('title', '')
summary = data.get('summary', '')

# Check if both title and summary are provided
if not title and not summary:
return jsonify({"error": "Title and summary are required"}), 400

# Define a prompt using the title and summary to generate content
prompt = (f"Write a detailed and informative blog post on the topic: '{title}'. "
f"Use the following summary as a reference: '{summary}'. "
"Make it engaging and informative, and elaborate based on the provided summary in 200 words.")

# Call the generative model with the title and summary prompt
model = palm.GenerativeModel('gemini-pro')
response = model.generate_content(prompt)

# Extract the generated content
content = response.text.strip() if response and response.text else "No content generated."

# Return the content as a JSON response
return jsonify({"content": content}), 200

except Exception as e:
print("Error:", str(e))
return jsonify({"error": "An error occurred while generating the content."}), 500


except Exception as e:
print("Error:", str(e))
return jsonify({"error": "An error occurred while generating the content."}), 500

@app.route('/analyze', methods=['GET'])
def health_check():
return jsonify({"message": "Server running!"}), 200

if __name__ == "__main__":
app.run(debug=True, port=8000)
48 changes: 0 additions & 48 deletions backend/generateTrendingTitles.py

This file was deleted.

85 changes: 80 additions & 5 deletions frontend/src/pages/AddBlog.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,23 @@ export function renderAddBlog(container) {
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 bg-white dark:bg-gray-700 text-gray-900 dark:text-white"></textarea>
</div>
<div class="mb-6">
<label for="excerpt" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Content</label>
<div class="mb-6 relative">
<label for="excerpt" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Content</label>
<div class="relative">
<!-- Button for generating content -->
<button id="generateContent" class="absolute top-2 right-2 text-2xl text-gray-500 dark:text-gray-300 hover:text-indigo-500 cursor-pointer" title="Generate AI Content">
<span class="tooltip absolute right-[95%] mr-2 hidden text-sm bg-gray-800 text-white p-1 rounded-md">
Generate AI Content
</span>
</button>
<!-- Textarea for content -->
<textarea id="excerpt" name="excerpt" rows="10" required
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 bg-white dark:bg-gray-700 text-gray-900 dark:text-white"></textarea>
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 bg-white dark:bg-gray-700 text-gray-900 dark:text-white"></textarea>
</div>
</div>
<div class="mb-6">
<label for="tags" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Tags (comma-separated)</label>
Expand All @@ -70,8 +82,71 @@ export function renderAddBlog(container) {
</div>
`;

// Add form submission logic
// Updated form submission logic

const generateContent = document.getElementById('generateContent');

generateContent.addEventListener('click', async function (e) {
const title = document.getElementById('title').value;
const summary = document.getElementById('summary').value;
const excerpt = document.getElementById('excerpt');

// Check if the title is empty
if (title === '' && summary === '') {
toastr.error('Enter title and summary for more relavant content');
return;
}

try {
// Configure toastr to keep the message displayed until manually cleared
toastr.options = {
timeOut: 0, // Infinite timeout
extendedTimeOut: 0, // Prevents auto-hiding on hover
tapToDismiss: false // Prevents closing on click
};

// Display the loading message
let loadingToastr = toastr.info('Your content is getting ready, please wait!');

// Fetch content from the API using title and summary
let response = await fetch('http://127.0.0.1:8000/generate-content', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ title: title, summary: summary })
});

// Clear the loading message after the response
toastr.clear(loadingToastr);

// Check if the response is successful
if (response.ok) {
let data = await response.json();

// Display generated content in the textarea
excerpt.value = data.content;

// Show success message
toastr.success('Content generated successfully!');
} else {
toastr.error('Failed to generate content. Please try again.');
}
} catch (error) {
console.error('Error:', error);
toastr.error('An error occurred. Please check the console for details.');
} finally {
// Clear the loading message in case of any error or completion
toastr.clear(loadingToastr);
}

});







const form = document.getElementById('add-blog-form');
form.addEventListener('submit', async function (e) {
e.preventDefault();
Expand Down
42 changes: 36 additions & 6 deletions frontend/src/styles/output.css
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,22 @@ video {
top: 0.75rem;
}

.right-2 {
right: 0.5rem;
}

.right-full {
right: 100%;
}

.top-2 {
top: 0.5rem;
}

.right-\[95\%\] {
right: 95%;
}

.z-10 {
z-index: 10;
}
Expand Down Expand Up @@ -831,7 +847,7 @@ video {
width: 28%;
}

.w-\[29\%\] {
.w-\[29\%\] {
width: 29%;
}

Expand All @@ -847,6 +863,7 @@ video {
max-width: 1280px;
}


.transform {
transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
}
Expand Down Expand Up @@ -1144,7 +1161,7 @@ video {
background-color: rgb(254 249 195 / var(--tw-bg-opacity));
}

.bg-green-500 {
.bg-green-500 {
--tw-bg-opacity: 1;
background-color: rgb(34 197 94 / var(--tw-bg-opacity));
}
Expand All @@ -1167,7 +1184,7 @@ video {
.to-purple-100 {
--tw-gradient-to: #f3e8ff var(--tw-gradient-to-position);
}

.object-cover {
-o-object-fit: cover;
object-fit: cover;
Expand Down Expand Up @@ -1197,9 +1214,11 @@ video {
padding: 2rem;
}

.p-5 {
.p-5 {
padding: 1.25rem;
}
.p-1 {
padding: 0.25rem;
}

.px-12 {
padding-left: 3rem;
Expand Down Expand Up @@ -1333,6 +1352,11 @@ video {
line-height: 1.75rem;
}

.text-xs {
font-size: 0.75rem;
line-height: 1rem;
}

.font-bold {
font-weight: 700;
}
Expand Down Expand Up @@ -1471,11 +1495,12 @@ video {
color: rgb(133 77 14 / var(--tw-text-opacity));
}

.text-indigo-400 {
.text-indigo-400 {
--tw-text-opacity: 1;
color: rgb(129 140 248 / var(--tw-text-opacity));
}


.shadow-lg {
--tw-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
--tw-shadow-colored: 0 10px 15px -3px var(--tw-shadow-color), 0 4px 6px -4px var(--tw-shadow-color);
Expand Down Expand Up @@ -1684,6 +1709,11 @@ body.dark-mode {
color: rgb(255 255 255 / var(--tw-text-opacity));
}

.hover\:text-indigo-500:hover {
--tw-text-opacity: 1;
color: rgb(99 102 241 / var(--tw-text-opacity));
}

.hover\:underline:hover {
text-decoration-line: underline;
}
Expand Down
Loading

0 comments on commit c29da5e

Please sign in to comment.