handling generate a post in the background
Browse files- Post_management.py +2 -2
- __pycache__/Post_management.cpython-311.pyc +0 -0
- __pycache__/functi.cpython-311.pyc +0 -0
- functi.py +20 -5
Post_management.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
from taipy import Gui
|
| 2 |
import taipy.gui.builder as tgb
|
| 3 |
-
from functi import post_generation,post_publishing,authen,add_scheduling,delete_account,delete_schedule
|
| 4 |
|
| 5 |
days_of_week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
|
| 6 |
Social_network_menu = ["Linkedin"]
|
|
@@ -28,7 +28,7 @@ with tgb.Page(class_name="bodyp") as Post_manag :
|
|
| 28 |
tgb.table("{data_account}", editable=True, on_add=False, on_edit=False, on_delete=delete_account, columns="social_network;account_name", width="100%")
|
| 29 |
with tgb.part(class_name="table_s") :
|
| 30 |
tgb.text("Demo", class_name="header-burgundy table_t")
|
| 31 |
-
tgb.button(label="Generate a post", on_action=
|
| 32 |
tgb.input("{generated_post}", multiline=True, class_name="burgundy-border", width="100%")
|
| 33 |
tgb.button(label="Publish", on_action=post_publishing, width="100%")
|
| 34 |
with tgb.part(class_name="table_s") :
|
|
|
|
| 1 |
from taipy import Gui
|
| 2 |
import taipy.gui.builder as tgb
|
| 3 |
+
from functi import post_generation,post_publishing,authen,add_scheduling,delete_account,delete_schedule,post_generation_
|
| 4 |
|
| 5 |
days_of_week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
|
| 6 |
Social_network_menu = ["Linkedin"]
|
|
|
|
| 28 |
tgb.table("{data_account}", editable=True, on_add=False, on_edit=False, on_delete=delete_account, columns="social_network;account_name", width="100%")
|
| 29 |
with tgb.part(class_name="table_s") :
|
| 30 |
tgb.text("Demo", class_name="header-burgundy table_t")
|
| 31 |
+
tgb.button(label="Generate a post", on_action=post_generation_, class_name="btn-burgundy", width="100%")
|
| 32 |
tgb.input("{generated_post}", multiline=True, class_name="burgundy-border", width="100%")
|
| 33 |
tgb.button(label="Publish", on_action=post_publishing, width="100%")
|
| 34 |
with tgb.part(class_name="table_s") :
|
__pycache__/Post_management.cpython-311.pyc
CHANGED
|
Binary files a/__pycache__/Post_management.cpython-311.pyc and b/__pycache__/Post_management.cpython-311.pyc differ
|
|
|
__pycache__/functi.cpython-311.pyc
CHANGED
|
Binary files a/__pycache__/functi.cpython-311.pyc and b/__pycache__/functi.cpython-311.pyc differ
|
|
|
functi.py
CHANGED
|
@@ -7,7 +7,7 @@ import time
|
|
| 7 |
import datetime
|
| 8 |
from line_db import DatabaseManager
|
| 9 |
from urllib.parse import urlencode
|
| 10 |
-
from taipy.gui import navigate # type: ignore
|
| 11 |
from gradio_client import Client
|
| 12 |
import pandas as pd
|
| 13 |
from requests_oauthlib import OAuth2Session
|
|
@@ -346,12 +346,27 @@ def post_publishing(state) :
|
|
| 346 |
resp = requests.post(url, headers=headers, json=body)
|
| 347 |
print([resp.status_code, resp.text],flush = True)
|
| 348 |
|
| 349 |
-
def post_generation(
|
| 350 |
-
|
| 351 |
-
code=
|
| 352 |
api_name="/poster_linkedin"
|
| 353 |
)
|
| 354 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 355 |
|
| 356 |
def authen(state) :
|
| 357 |
if state.Linked_social_network == "Linkedin" :
|
|
|
|
| 7 |
import datetime
|
| 8 |
from line_db import DatabaseManager
|
| 9 |
from urllib.parse import urlencode
|
| 10 |
+
from taipy.gui import navigate, invoke_long_callback, notify # type: ignore
|
| 11 |
from gradio_client import Client
|
| 12 |
import pandas as pd
|
| 13 |
from requests_oauthlib import OAuth2Session
|
|
|
|
| 346 |
resp = requests.post(url, headers=headers, json=body)
|
| 347 |
print([resp.status_code, resp.text],flush = True)
|
| 348 |
|
| 349 |
+
def post_generation(id) :
|
| 350 |
+
generated_post = client.predict(
|
| 351 |
+
code=id,
|
| 352 |
api_name="/poster_linkedin"
|
| 353 |
)
|
| 354 |
+
generated_post = eval(generated_post)
|
| 355 |
+
generated_post = generated_post[0]
|
| 356 |
+
return generated_post
|
| 357 |
+
|
| 358 |
+
def post_generation_status(state, status,result):
|
| 359 |
+
if status:
|
| 360 |
+
state.generated_post = result
|
| 361 |
+
notify(state, "success", "The heavy function has finished!")
|
| 362 |
+
else:
|
| 363 |
+
notify(state, "error", "The heavy function has failed")
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
def post_generation_(state):
|
| 367 |
+
id = state.user_inf.user.id
|
| 368 |
+
state.generated_post = " Generation en cours..."
|
| 369 |
+
invoke_long_callback(state,post_generation,[id],post_generation_status)
|
| 370 |
|
| 371 |
def authen(state) :
|
| 372 |
if state.Linked_social_network == "Linkedin" :
|