Spaces:
Running
Running
Commit
·
c50d4fc
1
Parent(s):
24b1a2e
Add SVG generation for mindmap using Gradio client in post generation
Browse files- post_blog.py +12 -2
post_blog.py
CHANGED
@@ -3,7 +3,7 @@ import time
|
|
3 |
import requests
|
4 |
import dotenv
|
5 |
import mistune
|
6 |
-
|
7 |
from image import fetch_image
|
8 |
|
9 |
dotenv.load_dotenv()
|
@@ -14,12 +14,22 @@ refresh_token = os.getenv('REFRESH_TOKEN')
|
|
14 |
blog_id = os.getenv('BLOG_ID')
|
15 |
imgbb_api_key = os.getenv('IMGBB_API_KEY')
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
def generate_post_html(title, summary, mindmap, citation):
|
18 |
title = title.replace("{", r'{').replace("}", r'}')
|
19 |
summary = summary.replace("{", r'{').replace("}", r'}')
|
20 |
mindmap = mindmap.replace("{", r'{').replace("}", r'}')
|
21 |
citation = citation.replace("{", r'{').replace("}", r'}')
|
22 |
image = fetch_image(title, summary, imgbb_api_key)
|
|
|
23 |
html_summary = mistune.html(summary)
|
24 |
post = f"""
|
25 |
<div id="paper_post">
|
@@ -72,7 +82,7 @@ def generate_post_html(title, summary, mindmap, citation):
|
|
72 |
<br>
|
73 |
<h2>Mindmap</h2>
|
74 |
<p><small><em>If MindMap doesn't load, go to the <a href="/">Homepage</a> and visit blog again or <a href="/#">Switch to Android App (Under Development)</a>.</em></small></p>
|
75 |
-
<div class="markmap" id="paper_mindmap">
|
76 |
<script type="text/template">
|
77 |
{mindmap.replace("&", "&").replace(":", "=>")}
|
78 |
</script>
|
|
|
3 |
import requests
|
4 |
import dotenv
|
5 |
import mistune
|
6 |
+
from gradio_client import Client
|
7 |
from image import fetch_image
|
8 |
|
9 |
dotenv.load_dotenv()
|
|
|
14 |
blog_id = os.getenv('BLOG_ID')
|
15 |
imgbb_api_key = os.getenv('IMGBB_API_KEY')
|
16 |
|
17 |
+
def generate_mindmap_svg(title, mindmap):
|
18 |
+
data = "# ",title , "\n" , mindmap
|
19 |
+
client = Client("raannakasturi/MarkdownToSVG")
|
20 |
+
result = client.predict(
|
21 |
+
markdown_text=data,
|
22 |
+
api_name="/markdown_svg_generator"
|
23 |
+
)
|
24 |
+
return result.strip("https:")
|
25 |
+
|
26 |
def generate_post_html(title, summary, mindmap, citation):
|
27 |
title = title.replace("{", r'{').replace("}", r'}')
|
28 |
summary = summary.replace("{", r'{').replace("}", r'}')
|
29 |
mindmap = mindmap.replace("{", r'{').replace("}", r'}')
|
30 |
citation = citation.replace("{", r'{').replace("}", r'}')
|
31 |
image = fetch_image(title, summary, imgbb_api_key)
|
32 |
+
svg_url = generate_mindmap_svg(title, mindmap)
|
33 |
html_summary = mistune.html(summary)
|
34 |
post = f"""
|
35 |
<div id="paper_post">
|
|
|
82 |
<br>
|
83 |
<h2>Mindmap</h2>
|
84 |
<p><small><em>If MindMap doesn't load, go to the <a href="/">Homepage</a> and visit blog again or <a href="/#">Switch to Android App (Under Development)</a>.</em></small></p>
|
85 |
+
<div class="markmap" id="paper_mindmap" data-markmap-url="{svg_url}">
|
86 |
<script type="text/template">
|
87 |
{mindmap.replace("&", "&").replace(":", "=>")}
|
88 |
</script>
|