teragron commited on
Commit
e8695e2
·
1 Parent(s): ab8324a

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +52 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datetime
2
+ import gradio as gr
3
+ import cv2
4
+ import uuid
5
+
6
+ def generate_markdown_post(title: str, content: str, image: gr.Image):
7
+ # Get the current date and time
8
+ now = datetime.datetime.now()
9
+
10
+ # Format the date and time in the required format
11
+ date_string = now.strftime("%Y-%m-%d %H:%M:%S %z")
12
+ subdate_string = now.strftime("%Y-%m-%d")
13
+
14
+ # Generate a random unique ID
15
+ unique_id = str(uuid.uuid4().hex)[:6]
16
+
17
+ # Format the filename with subdate and unique ID
18
+ filename = f"_posts/{subdate_string}-{unique_id}.markdown"
19
+
20
+ # Define the Markdown content with the updated title and date
21
+ markdown_content = f"""---
22
+ layout: post
23
+ title: "{title}"
24
+ date: {date_string}+200
25
+ categories: jekyll update
26
+ ---
27
+ <img src="/blog_assets/{unique_id}.jpg">
28
+
29
+ {content}
30
+ """
31
+
32
+ # Save the uploaded image to the file system
33
+
34
+ image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
35
+
36
+ cv2.imwrite(f"blog_assets/{unique_id}.jpg",image)
37
+
38
+ # Write the Markdown content to the file with the formatted filename
39
+ with open(filename, "w") as f:
40
+ f.write(markdown_content)
41
+
42
+ return f"Markdown post created at {filename}"
43
+
44
+ title = "Markdown Blog Post Generator"
45
+ description = "This app generates a Markdown blog post with the given title, content, and image."
46
+ inputs = [
47
+ gr.Textbox(label="Enter the blog post title:"),
48
+ gr.Textbox(label="Enter the content:"),
49
+ gr.Image(label="Upload an image")
50
+ ]
51
+ outputs = gr.Textbox()
52
+ gr.Interface(fn=generate_markdown_post, inputs=inputs, outputs=outputs, title=title, description=description).launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ opencv-python
2
+ gradio