mirror of
https://github.com/Paillat-dev/presentator.git
synced 2026-01-02 01:06:20 +00:00
some new things
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -153,5 +153,4 @@ cython_debug/
|
|||||||
token.env
|
token.env
|
||||||
key.env
|
key.env
|
||||||
|
|
||||||
707196665668436019
|
/data
|
||||||
1020254043597193226
|
|
||||||
7
imagesGeneration.py
Normal file
7
imagesGeneration.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import requests
|
||||||
|
import os
|
||||||
|
async def generate(prompt,path):
|
||||||
|
r = requests.get(f"http://localhost:8000/generate_image?prompt={prompt}&path={path}")
|
||||||
|
return r.json()
|
||||||
|
#print the current working directory
|
||||||
|
print(os.getcwd())
|
||||||
38
main.py
38
main.py
@@ -9,6 +9,7 @@ import asyncio
|
|||||||
import logging
|
import logging
|
||||||
import datetime
|
import datetime
|
||||||
import base64
|
import base64
|
||||||
|
import imagesGeneration
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
#we open the
|
#we open the
|
||||||
intstructions = '''Here is a presentation with marp. It's not possible to make slides longer than 200 characters. to separate slides,
|
intstructions = '''Here is a presentation with marp. It's not possible to make slides longer than 200 characters. to separate slides,
|
||||||
@@ -17,7 +18,7 @@ intstructions = '''Here is a presentation with marp. It's not possible to make s
|
|||||||
---
|
---
|
||||||
|
|
||||||
"
|
"
|
||||||
then go at the line. To add an image illustration , use  at the beginning of the slide, just after "---"-It's not possible to add technical images but only illustrations. The images are generated by an ai, the name of the file should be a detailed description of the image wanted. For example " " but son't need to show a person necessairly. The presentatio should be for everybody, all technical words and concepts, explained. The presentation is minimum 20 slides long. You can use bulletpoints. Use markdown formatting (titles, etc...). The presentation has also a conclusion.'''
|
then go at the line. To add an image illustration , use  at the beginning of the slide, just after "---"-It's not possible to add technical images but only illustrations. The images are generated by an ai, the name of the file should be a detailed description of the image wanted. For example " " but son't need to show a person necessairly. The presentatio should be for everybody, all technical words and concepts, explained. The presentation is minimum 20 slides long. You can use bulletpoints. Use markdown formatting (titles, etc...). The presentation has also a conclusion.'''
|
||||||
bot = discord.Bot()
|
bot = discord.Bot()
|
||||||
|
|
||||||
styles = ["default", "gaia", "uncover", "default-dark", "gaia-dark", "uncover-dark"]
|
styles = ["default", "gaia", "uncover", "default-dark", "gaia-dark", "uncover-dark"]
|
||||||
@@ -53,7 +54,7 @@ async def present(ctx: discord.ApplicationContext, subject: str, style: str = "d
|
|||||||
os.mkdir(uid)
|
os.mkdir(uid)
|
||||||
datenow = datetime.datetime.now()
|
datenow = datetime.datetime.now()
|
||||||
datenow = datenow.strftime("%Y-%m-%d-%H-%M-%S")
|
datenow = datenow.strftime("%Y-%m-%d-%H-%M-%S")
|
||||||
os.mkdir(f"{uid}/{b64}{datenow}")
|
os.mkdir(f"data/{uid}/{b64}{datenow}")
|
||||||
response = await openai.Completion.acreate(
|
response = await openai.Completion.acreate(
|
||||||
engine="text-davinci-003",
|
engine="text-davinci-003",
|
||||||
prompt=prompt,
|
prompt=prompt,
|
||||||
@@ -71,7 +72,7 @@ async def present(ctx: discord.ApplicationContext, subject: str, style: str = "d
|
|||||||
#we add the marp header
|
#we add the marp header
|
||||||
marp = f'''---
|
marp = f'''---
|
||||||
marp: true
|
marp: true
|
||||||
theme: {styles}
|
theme: {styles[styles.index(style)]}
|
||||||
class:
|
class:
|
||||||
- lead
|
- lead
|
||||||
'''
|
'''
|
||||||
@@ -86,24 +87,36 @@ class:
|
|||||||
for match in matches:
|
for match in matches:
|
||||||
image_filenames.append(match.group(1))
|
image_filenames.append(match.group(1))
|
||||||
#we create a text file with the image names and a md file for the presentation with utf8 encoding
|
#we create a text file with the image names and a md file for the presentation with utf8 encoding
|
||||||
with open(f"./{uid}/{b64}{datenow}/{subject}.md", "w", encoding="utf8") as f:
|
with open(f"./data/{uid}/{b64}{datenow}/{subject}.md", "w", encoding="utf8") as f:
|
||||||
f.write(present)
|
f.write(present)
|
||||||
with open(f"./{uid}/{b64}{datenow}/{subject}-images.txt", "w", encoding="utf8") as f:
|
with open(f"./data/{uid}/{b64}{datenow}/{subject}-images.txt", "w", encoding="utf8") as f:
|
||||||
for image in image_filenames:
|
for image in image_filenames:
|
||||||
f.write(image + "\n")
|
f.write(image + "\n")
|
||||||
|
#now we generate the images, if there are any
|
||||||
|
if len(image_filenames) > 0:
|
||||||
|
#now we first remove the extension from the image filenames by removing the last 4 characters
|
||||||
|
image_filenames = [image[:-4] for image in image_filenames]
|
||||||
|
print(image_filenames)
|
||||||
|
for images in image_filenames:
|
||||||
|
#we download the image
|
||||||
|
await imagesGeneration.generate(images, f"{os.getcwd()}\\data\\{uid}\\{b64}{datenow}\\")
|
||||||
|
#now we rename the image to remove the _0 from the end of the filename
|
||||||
|
os.rename(f"{os.getcwd()}\\data\\{uid}\\{b64}{datenow}\\{images}_0.png", f"{os.getcwd()}\\data\\{uid}\\{b64}{datenow}\\{images}.png")
|
||||||
|
#now we whait 10 seconds for discord to resume the websocket connection
|
||||||
|
await asyncio.sleep(10)
|
||||||
#we execute the command to convert the markdown file to a pdf and html file and also generate the first slide image
|
#we execute the command to convert the markdown file to a pdf and html file and also generate the first slide image
|
||||||
cmd = f"marp --pdf --allow-local-files ./{uid}/{b64}{datenow}/{subject}.md"
|
cmd = f"marp --pdf --allow-local-files ./data/{uid}/{b64}{datenow}/{subject}.md"
|
||||||
os.system(cmd)
|
os.system(cmd)
|
||||||
print(cmd)
|
print(cmd)
|
||||||
cmd = f"marp --image png -o ./{uid}/{b64}{datenow}/{subject}.png --allow-local-files ./{uid}/{b64}{datenow}/{subject}.md"
|
cmd = f"marp --image png -o ./data/{uid}/{b64}{datenow}/{subject}.png --allow-local-files ./data/{uid}/{b64}{datenow}/{subject}.md"
|
||||||
os.system(cmd)
|
os.system(cmd)
|
||||||
print(cmd)
|
print(cmd)
|
||||||
cmd = f"marp --html --allow-local-files ./{uid}/{b64}{datenow}/{subject}.md"
|
cmd = f"marp --html --allow-local-files ./data/{uid}/{b64}{datenow}/{subject}.md"
|
||||||
os.system(cmd)
|
os.system(cmd)
|
||||||
print(cmd)
|
print(cmd)
|
||||||
#we create an embed with the first slide imageand send it with the pdf file and the markdown file
|
#we create an embed with the first slide imageand send it with the pdf file and the markdown file
|
||||||
embed = discord.Embed(title=subject2, description="Thanks for using presentator bot. You can download the presentation in different formats (pdf, markdown, html). The images are generated by an ai. If you want to modify your presentation you can use the markdown file. More information about how to modify the file [HERE](https://marp.app).", color=0x00ff00)
|
embed = discord.Embed(title=subject2, description="Thanks for using presentator bot. You can download the presentation in different formats (pdf, markdown, html). The images are generated by an ai. If you want to modify your presentation you can use the markdown file. More information about how to modify the file [HERE](https://marp.app).", color=0xaaaaaa)
|
||||||
files = [discord.File(f"./{uid}/{b64}{datenow}/{subject}.pdf"), discord.File(f"./{uid}/{b64}{datenow}/{subject}.md"), discord.File(f"./{uid}/{b64}{datenow}/{subject}.html"), discord.File(f"./{uid}/{b64}{datenow}/{subject}.png")]
|
files = [discord.File(f"./data/{uid}/{b64}{datenow}/{subject}.pdf"), discord.File(f"./data/{uid}/{b64}{datenow}/{subject}.md"), discord.File(f"./data/{uid}/{b64}{datenow}/{subject}.html"), discord.File(f"./data/{uid}/{b64}{datenow}/{subject}.png")]
|
||||||
embed.set_image(url=f"attachment://{subject}.png")
|
embed.set_image(url=f"attachment://{subject}.png")
|
||||||
#now we send the embed and all the 4 files (pdf, markdown, html, png) at the same time
|
#now we send the embed and all the 4 files (pdf, markdown, html, png) at the same time
|
||||||
await ctx.respond(embed=embed, files=files)
|
await ctx.respond(embed=embed, files=files)
|
||||||
@@ -137,12 +150,15 @@ async def get(ctx: discord.ApplicationContext, pid: str):
|
|||||||
#we check if the presentation id is in the list
|
#we check if the presentation id is in the list
|
||||||
if pid in liste:
|
if pid in liste:
|
||||||
#if it is we send the pdf, markdown and html files
|
#if it is we send the pdf, markdown and html files
|
||||||
files = [discord.File(f"./{uid}/{pid}/{liste[pid]}.pdf"), discord.File(f"./{uid}/{pid}/{liste[pid]}.md"), discord.File(f"./{uid}/{pid}/{liste[pid]}.html")]
|
files = [discord.File(f"./data/{uid}/{pid}/{liste[pid]}.pdf"), discord.File(f"./data/{uid}/{pid}/{liste[pid]}.md"), discord.File(f"./data/{uid}/{pid}/{liste[pid]}.html")]
|
||||||
await ctx.respond(files=files, ephemeral=True)
|
await ctx.respond(files=files, ephemeral=True)
|
||||||
#when the bot is ready we print a message
|
#when the bot is ready we print a message
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
print("Bot is ready")
|
print("Bot is ready")
|
||||||
|
#if the data directory doesn't exist we create it
|
||||||
|
if not os.path.exists("data"):
|
||||||
|
os.mkdir("data")
|
||||||
#get the openai key drom he key.env file
|
#get the openai key drom he key.env file
|
||||||
with open("key.env", "r") as f:
|
with open("key.env", "r") as f:
|
||||||
apikey = f.read()
|
apikey = f.read()
|
||||||
|
|||||||
Reference in New Issue
Block a user