kk
Browse files- backend/__init__.py +2 -0
- backend/api/posts.py +53 -9
- backend/models/post.py +2 -2
- backend/services/content_service.py +57 -3
- backend/services/linkedin_service.py +3 -2
- frontend/src/pages/Posts.jsx +79 -5
- frontend/src/store/reducers/postsSlice.js +6 -2
- frontend/vite.config.js +1 -1
- package.json +3 -2
- start-dev.js +47 -0
backend/__init__.py
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
# backend/__init__.py
|
2 |
+
# This file makes the backend directory a Python package
|
backend/api/posts.py
CHANGED
@@ -141,12 +141,23 @@ def _generate_post_task(user_id, job_id, job_store, hugging_key):
|
|
141 |
# Generate content using content service
|
142 |
# Pass the Hugging Face key directly to the service
|
143 |
content_service = ContentService(hugging_key=hugging_key)
|
144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
|
146 |
# Update job status to completed with result
|
147 |
job_store[job_id] = {
|
148 |
'status': 'completed',
|
149 |
-
'result':
|
|
|
|
|
|
|
150 |
'error': None
|
151 |
}
|
152 |
|
@@ -248,7 +259,25 @@ def get_job_status(job_id):
|
|
248 |
|
249 |
# Include result or error if available
|
250 |
if job['status'] == 'completed':
|
251 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
252 |
elif job['status'] == 'failed':
|
253 |
response_data['error'] = job['error']
|
254 |
|
@@ -335,12 +364,24 @@ def publish_post_direct():
|
|
335 |
}), 400
|
336 |
|
337 |
# Get optional fields
|
338 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
339 |
|
340 |
# Publish to LinkedIn
|
341 |
linkedin_service = LinkedInService()
|
342 |
publish_response = linkedin_service.publish_post(
|
343 |
-
access_token, user_sub, text_content,
|
344 |
)
|
345 |
|
346 |
# Save to database as published
|
@@ -351,8 +392,8 @@ def publish_post_direct():
|
|
351 |
}
|
352 |
|
353 |
# Add optional fields if provided
|
354 |
-
if
|
355 |
-
post_data['image_content_url'] =
|
356 |
|
357 |
if 'scheduled_at' in data:
|
358 |
post_data['scheduled_at'] = data['scheduled_at']
|
@@ -462,9 +503,12 @@ def create_post():
|
|
462 |
'is_published': data.get('is_published', True) # Default to True
|
463 |
}
|
464 |
|
|
|
|
|
|
|
465 |
# Add optional fields if provided
|
466 |
-
if
|
467 |
-
post_data['image_content_url'] =
|
468 |
|
469 |
if 'scheduled_at' in data:
|
470 |
post_data['scheduled_at'] = data['scheduled_at']
|
|
|
141 |
# Generate content using content service
|
142 |
# Pass the Hugging Face key directly to the service
|
143 |
content_service = ContentService(hugging_key=hugging_key)
|
144 |
+
generated_result = content_service.generate_post_content(user_id)
|
145 |
+
|
146 |
+
# Handle the case where generated_result might be a tuple (content, image_data)
|
147 |
+
# image_data could be bytes (from base64) or a string (URL)
|
148 |
+
if isinstance(generated_result, tuple):
|
149 |
+
generated_content, image_data = generated_result
|
150 |
+
else:
|
151 |
+
generated_content = generated_result
|
152 |
+
image_data = None
|
153 |
|
154 |
# Update job status to completed with result
|
155 |
job_store[job_id] = {
|
156 |
'status': 'completed',
|
157 |
+
'result': {
|
158 |
+
'content': generated_content,
|
159 |
+
'image_data': image_data # This could be bytes or a URL string
|
160 |
+
},
|
161 |
'error': None
|
162 |
}
|
163 |
|
|
|
259 |
|
260 |
# Include result or error if available
|
261 |
if job['status'] == 'completed':
|
262 |
+
# Handle the new structure of the result
|
263 |
+
if isinstance(job['result'], dict) and 'content' in job['result']:
|
264 |
+
response_data['content'] = job['result']['content']
|
265 |
+
# Handle image_data which could be bytes or a URL string
|
266 |
+
image_data = job['result'].get('image_data')
|
267 |
+
if isinstance(image_data, bytes):
|
268 |
+
# If it's bytes, we can't send it directly in JSON
|
269 |
+
# For now, we'll set it to None and let the frontend know
|
270 |
+
# In a future update, we might save it to storage and return a URL
|
271 |
+
response_data['image_url'] = None
|
272 |
+
response_data['has_image_data'] = True # Flag to indicate image data exists
|
273 |
+
else:
|
274 |
+
# If it's a string, assume it's a URL
|
275 |
+
response_data['image_url'] = image_data
|
276 |
+
response_data['has_image_data'] = False
|
277 |
+
else:
|
278 |
+
response_data['content'] = job['result']
|
279 |
+
response_data['image_url'] = None
|
280 |
+
response_data['has_image_data'] = False
|
281 |
elif job['status'] == 'failed':
|
282 |
response_data['error'] = job['error']
|
283 |
|
|
|
364 |
}), 400
|
365 |
|
366 |
# Get optional fields
|
367 |
+
image_data = data.get('image_content_url') # This could be bytes or a URL string
|
368 |
+
|
369 |
+
# Handle image data - if it's bytes, we need to convert it for LinkedIn
|
370 |
+
image_url_for_linkedin = None
|
371 |
+
if image_data:
|
372 |
+
if isinstance(image_data, bytes):
|
373 |
+
# If it's bytes, we can't directly send it to LinkedIn
|
374 |
+
# For now, we'll skip sending the image to LinkedIn
|
375 |
+
# In a future update, we might save it to storage and get a URL
|
376 |
+
current_app.logger.warning("Image data is in bytes format, skipping LinkedIn upload for now")
|
377 |
+
else:
|
378 |
+
# If it's a string, assume it's a URL
|
379 |
+
image_url_for_linkedin = image_data
|
380 |
|
381 |
# Publish to LinkedIn
|
382 |
linkedin_service = LinkedInService()
|
383 |
publish_response = linkedin_service.publish_post(
|
384 |
+
access_token, user_sub, text_content, image_url_for_linkedin
|
385 |
)
|
386 |
|
387 |
# Save to database as published
|
|
|
392 |
}
|
393 |
|
394 |
# Add optional fields if provided
|
395 |
+
if image_data:
|
396 |
+
post_data['image_content_url'] = image_data
|
397 |
|
398 |
if 'scheduled_at' in data:
|
399 |
post_data['scheduled_at'] = data['scheduled_at']
|
|
|
503 |
'is_published': data.get('is_published', True) # Default to True
|
504 |
}
|
505 |
|
506 |
+
# Handle image data - could be bytes or a URL string
|
507 |
+
image_data = data.get('image_content_url')
|
508 |
+
|
509 |
# Add optional fields if provided
|
510 |
+
if image_data is not None:
|
511 |
+
post_data['image_content_url'] = image_data
|
512 |
|
513 |
if 'scheduled_at' in data:
|
514 |
post_data['scheduled_at'] = data['scheduled_at']
|
backend/models/post.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
from dataclasses import dataclass
|
2 |
-
from typing import Optional
|
3 |
from datetime import datetime
|
4 |
|
5 |
@dataclass
|
@@ -10,7 +10,7 @@ class Post:
|
|
10 |
Text_content: str
|
11 |
is_published: bool = True
|
12 |
sched: Optional[str] = None
|
13 |
-
image_content_url: Optional[str] = None
|
14 |
created_at: Optional[datetime] = None
|
15 |
scheduled_at: Optional[datetime] = None
|
16 |
|
|
|
1 |
from dataclasses import dataclass
|
2 |
+
from typing import Optional, Union
|
3 |
from datetime import datetime
|
4 |
|
5 |
@dataclass
|
|
|
10 |
Text_content: str
|
11 |
is_published: bool = True
|
12 |
sched: Optional[str] = None
|
13 |
+
image_content_url: Optional[Union[str, bytes]] = None # Can be URL string or bytes
|
14 |
created_at: Optional[datetime] = None
|
15 |
scheduled_at: Optional[datetime] = None
|
16 |
|
backend/services/content_service.py
CHANGED
@@ -1,9 +1,12 @@
|
|
1 |
import re
|
2 |
import json
|
3 |
import unicodedata
|
|
|
4 |
from flask import current_app
|
5 |
from gradio_client import Client
|
6 |
import pandas as pd
|
|
|
|
|
7 |
|
8 |
class ContentService:
|
9 |
"""Service for AI content generation using Hugging Face models."""
|
@@ -66,7 +69,45 @@ class ContentService:
|
|
66 |
|
67 |
return validated
|
68 |
|
69 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
"""
|
71 |
Generate post content using AI.
|
72 |
|
@@ -74,7 +115,7 @@ class ContentService:
|
|
74 |
user_id (str): User ID for personalization
|
75 |
|
76 |
Returns:
|
77 |
-
|
78 |
"""
|
79 |
try:
|
80 |
# Call the Hugging Face model to generate content
|
@@ -100,8 +141,11 @@ class ContentService:
|
|
100 |
# Extract the first element if it's a list
|
101 |
if isinstance(parsed_result, list):
|
102 |
generated_content = parsed_result[0] if parsed_result and parsed_result[0] is not None else "Generated content will appear here..."
|
|
|
|
|
103 |
else:
|
104 |
generated_content = str(parsed_result) if parsed_result is not None else "Generated content will appear here..."
|
|
|
105 |
|
106 |
# Validate, sanitize, and preserve formatting of the generated content
|
107 |
sanitized_content = self.sanitize_content_for_api(generated_content)
|
@@ -109,7 +153,17 @@ class ContentService:
|
|
109 |
# Ensure paragraph breaks and formatting are preserved
|
110 |
final_content = self.preserve_formatting(sanitized_content)
|
111 |
|
112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
|
114 |
except Exception as e:
|
115 |
error_message = str(e)
|
|
|
1 |
import re
|
2 |
import json
|
3 |
import unicodedata
|
4 |
+
import io
|
5 |
from flask import current_app
|
6 |
from gradio_client import Client
|
7 |
import pandas as pd
|
8 |
+
from PIL import Image
|
9 |
+
import base64
|
10 |
|
11 |
class ContentService:
|
12 |
"""Service for AI content generation using Hugging Face models."""
|
|
|
69 |
|
70 |
return validated
|
71 |
|
72 |
+
def _is_base64_image(self, data):
|
73 |
+
"""Check if the data is a base64 encoded image string."""
|
74 |
+
if not isinstance(data, str):
|
75 |
+
return False
|
76 |
+
|
77 |
+
# Check if it starts with data URL prefix
|
78 |
+
if data.startswith('data:image/'):
|
79 |
+
return True
|
80 |
+
|
81 |
+
# Try to decode as base64
|
82 |
+
try:
|
83 |
+
# Extract base64 part if it's a data URL
|
84 |
+
if ',' in data:
|
85 |
+
base64_part = data.split(',')[1]
|
86 |
+
else:
|
87 |
+
base64_part = data
|
88 |
+
|
89 |
+
# Try to decode
|
90 |
+
base64.b64decode(base64_part, validate=True)
|
91 |
+
return True
|
92 |
+
except Exception:
|
93 |
+
return False
|
94 |
+
|
95 |
+
def _base64_to_bytes(self, base64_string):
|
96 |
+
"""Convert a base64 encoded string to bytes."""
|
97 |
+
try:
|
98 |
+
# If it's a data URL, extract the base64 part
|
99 |
+
if base64_string.startswith('data:image/'):
|
100 |
+
base64_part = base64_string.split(',')[1]
|
101 |
+
else:
|
102 |
+
base64_part = base64_string
|
103 |
+
|
104 |
+
# Decode base64 to bytes
|
105 |
+
return base64.b64decode(base64_part, validate=True)
|
106 |
+
except Exception as e:
|
107 |
+
current_app.logger.error(f"Failed to decode base64 image: {str(e)}")
|
108 |
+
raise Exception(f"Failed to decode base64 image: {str(e)}")
|
109 |
+
|
110 |
+
def generate_post_content(self, user_id: str) -> tuple:
|
111 |
"""
|
112 |
Generate post content using AI.
|
113 |
|
|
|
115 |
user_id (str): User ID for personalization
|
116 |
|
117 |
Returns:
|
118 |
+
tuple: (Generated post content, Image URL or None)
|
119 |
"""
|
120 |
try:
|
121 |
# Call the Hugging Face model to generate content
|
|
|
141 |
# Extract the first element if it's a list
|
142 |
if isinstance(parsed_result, list):
|
143 |
generated_content = parsed_result[0] if parsed_result and parsed_result[0] is not None else "Generated content will appear here..."
|
144 |
+
# Extract the second element as image URL if it exists
|
145 |
+
image_data = parsed_result[1] if len(parsed_result) > 1 and parsed_result[1] is not None else None
|
146 |
else:
|
147 |
generated_content = str(parsed_result) if parsed_result is not None else "Generated content will appear here..."
|
148 |
+
image_data = None
|
149 |
|
150 |
# Validate, sanitize, and preserve formatting of the generated content
|
151 |
sanitized_content = self.sanitize_content_for_api(generated_content)
|
|
|
153 |
# Ensure paragraph breaks and formatting are preserved
|
154 |
final_content = self.preserve_formatting(sanitized_content)
|
155 |
|
156 |
+
# Handle image data - could be URL or base64
|
157 |
+
image_bytes = None
|
158 |
+
if image_data:
|
159 |
+
if self._is_base64_image(image_data):
|
160 |
+
# Convert base64 to bytes for storage
|
161 |
+
image_bytes = self._base64_to_bytes(image_data)
|
162 |
+
else:
|
163 |
+
# It's a URL, keep as string
|
164 |
+
image_bytes = image_data
|
165 |
+
|
166 |
+
return (final_content, image_bytes)
|
167 |
|
168 |
except Exception as e:
|
169 |
error_message = str(e)
|
backend/services/linkedin_service.py
CHANGED
@@ -130,7 +130,7 @@ class LinkedInService:
|
|
130 |
access_token (str): LinkedIn access token
|
131 |
user_id (str): LinkedIn user ID
|
132 |
text_content (str): Post content
|
133 |
-
image_url (str, optional): Image URL
|
134 |
|
135 |
Returns:
|
136 |
dict: Publish response
|
@@ -142,7 +142,8 @@ class LinkedInService:
|
|
142 |
"Content-Type": "application/json"
|
143 |
}
|
144 |
|
145 |
-
if image_url
|
|
|
146 |
# Handle image upload
|
147 |
register_body = {
|
148 |
"registerUploadRequest": {
|
|
|
130 |
access_token (str): LinkedIn access token
|
131 |
user_id (str): LinkedIn user ID
|
132 |
text_content (str): Post content
|
133 |
+
image_url (str, optional): Image URL (must be a URL, not bytes)
|
134 |
|
135 |
Returns:
|
136 |
dict: Publish response
|
|
|
142 |
"Content-Type": "application/json"
|
143 |
}
|
144 |
|
145 |
+
# Skip image handling if image_url is not a string (i.e., if it's bytes)
|
146 |
+
if image_url and isinstance(image_url, str):
|
147 |
# Handle image upload
|
148 |
register_body = {
|
149 |
"registerUploadRequest": {
|
frontend/src/pages/Posts.jsx
CHANGED
@@ -22,6 +22,7 @@ const Posts = () => {
|
|
22 |
|
23 |
const [selectedAccount, setSelectedAccount] = useState('');
|
24 |
const [postContent, setPostContent] = useState('');
|
|
|
25 |
const [isGenerating, setIsGenerating] = useState(false);
|
26 |
const [isCreating, setIsCreating] = useState(false);
|
27 |
|
@@ -34,19 +35,33 @@ const Posts = () => {
|
|
34 |
|
35 |
const handleGeneratePost = async () => {
|
36 |
setIsGenerating(true);
|
|
|
37 |
|
38 |
try {
|
39 |
const result = await dispatch(generatePost()).unwrap();
|
40 |
|
41 |
// Handle case where content might be a list
|
42 |
let content = result.content || 'Generated content will appear here...';
|
|
|
43 |
|
44 |
-
// If content is an array,
|
45 |
if (Array.isArray(content)) {
|
46 |
content = content[0] || 'Generated content will appear here...';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
}
|
48 |
|
49 |
setPostContent(content);
|
|
|
50 |
} catch (err) {
|
51 |
console.error('Failed to generate post:', err);
|
52 |
// Show a user-friendly error message
|
@@ -73,26 +88,42 @@ const Posts = () => {
|
|
73 |
try {
|
74 |
// Publish directly to LinkedIn
|
75 |
console.log('π [Posts] Publishing to LinkedIn');
|
76 |
-
const
|
77 |
social_account_id: selectedAccount,
|
78 |
text_content: postContent
|
79 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
console.log('π [Posts] Published to LinkedIn successfully:', publishResult);
|
82 |
|
83 |
// Only save to database if LinkedIn publish was successful
|
84 |
console.log('π [Posts] Saving post to database as published');
|
85 |
-
|
86 |
social_account_id: selectedAccount,
|
87 |
text_content: postContent,
|
88 |
is_published: true // Mark as published since we've already published it
|
89 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
|
91 |
console.log('π [Posts] Post saved to database');
|
92 |
|
93 |
// Reset form
|
94 |
setSelectedAccount('');
|
95 |
setPostContent('');
|
|
|
|
|
96 |
} catch (err) {
|
97 |
console.error('π [Posts] Failed to publish post:', err);
|
98 |
// Don't save to database if LinkedIn publish failed
|
@@ -111,6 +142,11 @@ const Posts = () => {
|
|
111 |
|
112 |
const handleContentChange = (content) => {
|
113 |
setPostContent(content);
|
|
|
|
|
|
|
|
|
|
|
114 |
};
|
115 |
|
116 |
// Filter published posts
|
@@ -319,6 +355,44 @@ const Posts = () => {
|
|
319 |
</div>
|
320 |
</div>
|
321 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
322 |
{/* Create Post Form */}
|
323 |
<form onSubmit={handleCreatePost} className="create-post-form grid grid-cols-1 sm:grid-cols-3 gap-3 sm:gap-4">
|
324 |
<div className="form-field sm:col-span-2">
|
|
|
22 |
|
23 |
const [selectedAccount, setSelectedAccount] = useState('');
|
24 |
const [postContent, setPostContent] = useState('');
|
25 |
+
const [postImage, setPostImage] = useState(null); // State for image URL
|
26 |
const [isGenerating, setIsGenerating] = useState(false);
|
27 |
const [isCreating, setIsCreating] = useState(false);
|
28 |
|
|
|
35 |
|
36 |
const handleGeneratePost = async () => {
|
37 |
setIsGenerating(true);
|
38 |
+
setPostImage(null); // Reset image when generating new post
|
39 |
|
40 |
try {
|
41 |
const result = await dispatch(generatePost()).unwrap();
|
42 |
|
43 |
// Handle case where content might be a list
|
44 |
let content = result.content || 'Generated content will appear here...';
|
45 |
+
let image = null;
|
46 |
|
47 |
+
// If content is an array, handle both content and image
|
48 |
if (Array.isArray(content)) {
|
49 |
content = content[0] || 'Generated content will appear here...';
|
50 |
+
image = content[1] || null; // Second element might be image URL
|
51 |
+
}
|
52 |
+
// If result has image_url property (from backend)
|
53 |
+
else if (result.image_url) {
|
54 |
+
image = result.image_url;
|
55 |
+
}
|
56 |
+
// If result has has_image_data property, it means image data exists but is in bytes
|
57 |
+
else if (result.has_image_data) {
|
58 |
+
// For now, we'll just show a placeholder or message
|
59 |
+
// In a future update, we might fetch the image data separately
|
60 |
+
image = 'HAS_IMAGE_DATA_BUT_NOT_URL'; // Special marker
|
61 |
}
|
62 |
|
63 |
setPostContent(content);
|
64 |
+
setPostImage(image);
|
65 |
} catch (err) {
|
66 |
console.error('Failed to generate post:', err);
|
67 |
// Show a user-friendly error message
|
|
|
88 |
try {
|
89 |
// Publish directly to LinkedIn
|
90 |
console.log('π [Posts] Publishing to LinkedIn');
|
91 |
+
const publishData = {
|
92 |
social_account_id: selectedAccount,
|
93 |
text_content: postContent
|
94 |
+
};
|
95 |
+
|
96 |
+
// Add image URL if available
|
97 |
+
if (postImage) {
|
98 |
+
publishData.image_content_url = postImage;
|
99 |
+
}
|
100 |
+
|
101 |
+
const publishResult = await dispatch(publishPostDirect(publishData)).unwrap();
|
102 |
|
103 |
console.log('π [Posts] Published to LinkedIn successfully:', publishResult);
|
104 |
|
105 |
// Only save to database if LinkedIn publish was successful
|
106 |
console.log('π [Posts] Saving post to database as published');
|
107 |
+
const createData = {
|
108 |
social_account_id: selectedAccount,
|
109 |
text_content: postContent,
|
110 |
is_published: true // Mark as published since we've already published it
|
111 |
+
};
|
112 |
+
|
113 |
+
// Add image URL if available
|
114 |
+
if (postImage) {
|
115 |
+
createData.image_content_url = postImage;
|
116 |
+
}
|
117 |
+
|
118 |
+
await dispatch(createPost(createData)).unwrap();
|
119 |
|
120 |
console.log('π [Posts] Post saved to database');
|
121 |
|
122 |
// Reset form
|
123 |
setSelectedAccount('');
|
124 |
setPostContent('');
|
125 |
+
setPostImage(null);
|
126 |
+
setPostImage(null);
|
127 |
} catch (err) {
|
128 |
console.error('π [Posts] Failed to publish post:', err);
|
129 |
// Don't save to database if LinkedIn publish failed
|
|
|
142 |
|
143 |
const handleContentChange = (content) => {
|
144 |
setPostContent(content);
|
145 |
+
// If user manually edits content, we should clear the AI-generated image
|
146 |
+
// as it might no longer be relevant
|
147 |
+
if (postImage) {
|
148 |
+
setPostImage(null);
|
149 |
+
}
|
150 |
};
|
151 |
|
152 |
// Filter published posts
|
|
|
355 |
</div>
|
356 |
</div>
|
357 |
|
358 |
+
{/* Image Preview */}
|
359 |
+
{postImage && postImage !== 'HAS_IMAGE_DATA_BUT_NOT_URL' && (
|
360 |
+
<div className="space-y-3 sm:space-y-4">
|
361 |
+
<label className="block text-xs sm:text-sm font-semibold text-gray-700">Generated Image</label>
|
362 |
+
<div className="relative border border-gray-300 rounded-xl overflow-hidden bg-gray-50">
|
363 |
+
<img
|
364 |
+
src={postImage}
|
365 |
+
alt="Generated post content"
|
366 |
+
className="w-full max-h-96 object-contain"
|
367 |
+
onError={(e) => {
|
368 |
+
// If image fails to load, remove it from state
|
369 |
+
setPostImage(null);
|
370 |
+
e.target.style.display = 'none';
|
371 |
+
}}
|
372 |
+
/>
|
373 |
+
<div className="absolute top-2 right-2 bg-black/50 text-white text-xs px-2 py-1 rounded">
|
374 |
+
AI Generated
|
375 |
+
</div>
|
376 |
+
</div>
|
377 |
+
</div>
|
378 |
+
)}
|
379 |
+
|
380 |
+
{/* Image Data Exists Message */}
|
381 |
+
{postImage === 'HAS_IMAGE_DATA_BUT_NOT_URL' && (
|
382 |
+
<div className="space-y-3 sm:space-y-4">
|
383 |
+
<label className="block text-xs sm:text-sm font-semibold text-gray-700">Generated Image</label>
|
384 |
+
<div className="relative border border-gray-300 rounded-xl overflow-hidden bg-gray-50 p-4">
|
385 |
+
<div className="text-center text-gray-500">
|
386 |
+
<svg className="w-12 h-12 mx-auto mb-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
387 |
+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" />
|
388 |
+
</svg>
|
389 |
+
<p className="text-sm">Image data exists but cannot be displayed directly</p>
|
390 |
+
<p className="text-xs mt-1">The image will be included when you publish the post</p>
|
391 |
+
</div>
|
392 |
+
</div>
|
393 |
+
</div>
|
394 |
+
)}
|
395 |
+
|
396 |
{/* Create Post Form */}
|
397 |
<form onSubmit={handleCreatePost} className="create-post-form grid grid-cols-1 sm:grid-cols-3 gap-3 sm:gap-4">
|
398 |
<div className="form-field sm:col-span-2">
|
frontend/src/store/reducers/postsSlice.js
CHANGED
@@ -91,10 +91,14 @@ const postsSlice = createSlice({
|
|
91 |
},
|
92 |
updatePostContent: (state, action) => {
|
93 |
// This reducer can be used to update post content in the store
|
94 |
-
const { postId, content } = action.payload;
|
95 |
const postIndex = state.items.findIndex(item => item.id === postId);
|
96 |
if (postIndex !== -1) {
|
97 |
-
state.items[postIndex] = {
|
|
|
|
|
|
|
|
|
98 |
}
|
99 |
}
|
100 |
},
|
|
|
91 |
},
|
92 |
updatePostContent: (state, action) => {
|
93 |
// This reducer can be used to update post content in the store
|
94 |
+
const { postId, content, image } = action.payload;
|
95 |
const postIndex = state.items.findIndex(item => item.id === postId);
|
96 |
if (postIndex !== -1) {
|
97 |
+
state.items[postIndex] = {
|
98 |
+
...state.items[postIndex],
|
99 |
+
Text_content: content,
|
100 |
+
...(image && { image_content_url: image }) // Only update image if provided
|
101 |
+
};
|
102 |
}
|
103 |
}
|
104 |
},
|
frontend/vite.config.js
CHANGED
@@ -16,7 +16,7 @@ export default defineConfig({
|
|
16 |
},
|
17 |
server: {
|
18 |
port: 3000,
|
19 |
-
host:
|
20 |
proxy: {
|
21 |
'/api': {
|
22 |
target: 'http://localhost:5000',
|
|
|
16 |
},
|
17 |
server: {
|
18 |
port: 3000,
|
19 |
+
host: 'localhost', // Explicitly bind to localhost
|
20 |
proxy: {
|
21 |
'/api': {
|
22 |
target: 'http://localhost:5000',
|
package.json
CHANGED
@@ -9,8 +9,9 @@
|
|
9 |
"install:all": "npm run install:frontend && npm run install:backend",
|
10 |
"install:all:win": "npm run install:frontend && cd backend && python -m pip install -r requirements.txt",
|
11 |
"dev:frontend": "cd frontend && npm run dev",
|
12 |
-
"dev:backend": "cd backend && python app.py",
|
13 |
"dev:all": "concurrently \"npm run dev:frontend\" \"npm run dev:backend\"",
|
|
|
14 |
"build": "cd frontend && npm run build",
|
15 |
"build:prod": "cd frontend && npm run build:prod",
|
16 |
"preview": "cd frontend && npm run preview",
|
@@ -47,4 +48,4 @@
|
|
47 |
"dependencies": {
|
48 |
"@rushstack/eslint-patch": "^1.12.0"
|
49 |
}
|
50 |
-
}
|
|
|
9 |
"install:all": "npm run install:frontend && npm run install:backend",
|
10 |
"install:all:win": "npm run install:frontend && cd backend && python -m pip install -r requirements.txt",
|
11 |
"dev:frontend": "cd frontend && npm run dev",
|
12 |
+
"dev:backend": "cd backend && set PYTHONPATH=. && python app.py",
|
13 |
"dev:all": "concurrently \"npm run dev:frontend\" \"npm run dev:backend\"",
|
14 |
+
"dev": "concurrently \"npm run dev:frontend\" \"npm run dev:backend\"",
|
15 |
"build": "cd frontend && npm run build",
|
16 |
"build:prod": "cd frontend && npm run build:prod",
|
17 |
"preview": "cd frontend && npm run preview",
|
|
|
48 |
"dependencies": {
|
49 |
"@rushstack/eslint-patch": "^1.12.0"
|
50 |
}
|
51 |
+
}
|
start-dev.js
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const { spawn } = require('child_process');
|
2 |
+
const path = require('path');
|
3 |
+
|
4 |
+
console.log('π Starting Lin Development Environment...');
|
5 |
+
console.log('==========================================\n');
|
6 |
+
|
7 |
+
// Start backend process
|
8 |
+
console.log('π§ Starting Backend Server...');
|
9 |
+
const backend = spawn('python', ['app.py'], {
|
10 |
+
cwd: path.join(__dirname, 'backend'),
|
11 |
+
stdio: 'inherit',
|
12 |
+
shell: true
|
13 |
+
});
|
14 |
+
|
15 |
+
// Start frontend process
|
16 |
+
console.log('π¨ Starting Frontend Development Server...');
|
17 |
+
const frontend = spawn('npm', ['run', 'dev'], {
|
18 |
+
cwd: path.join(__dirname, 'frontend'),
|
19 |
+
stdio: 'inherit',
|
20 |
+
shell: true
|
21 |
+
});
|
22 |
+
|
23 |
+
// Handle process events
|
24 |
+
backend.on('close', (code) => {
|
25 |
+
console.log(`Backend process exited with code ${code}`);
|
26 |
+
frontend.kill();
|
27 |
+
});
|
28 |
+
|
29 |
+
frontend.on('close', (code) => {
|
30 |
+
console.log(`Frontend process exited with code ${code}`);
|
31 |
+
backend.kill();
|
32 |
+
});
|
33 |
+
|
34 |
+
// Handle exit signals
|
35 |
+
process.on('SIGINT', () => {
|
36 |
+
console.log('\nπ Shutting down development servers...');
|
37 |
+
backend.kill();
|
38 |
+
frontend.kill();
|
39 |
+
process.exit(0);
|
40 |
+
});
|
41 |
+
|
42 |
+
process.on('SIGTERM', () => {
|
43 |
+
console.log('\nπ Shutting down development servers...');
|
44 |
+
backend.kill();
|
45 |
+
frontend.kill();
|
46 |
+
process.exit(0);
|
47 |
+
});
|