Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
krishpy99 committed May 19, 2024
1 parent 3b5f8c2 commit a84d8ce
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 10 deletions.
Binary file added __pycache__/app.cpython-312.pyc
Binary file not shown.
8 changes: 6 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ async def read_form():
async def submit_form(topic: str = Form(...)):
prompt = gen.get_prompt(topic)
res = gen.write_article(prompt)
res = write_blog(res["title"], res["content"], res["tags"])
return {"res": res}
_ = write_blog(res["title"], res["content"], res["tags"])
return {
"title": res["title"],
"content": res["content"],
"tags": res["tags"]
}

@app.get("/write")
def read_root():
Expand Down
Binary file added helpers/__pycache__/ai.cpython-312.pyc
Binary file not shown.
Binary file added helpers/__pycache__/blog.cpython-312.pyc
Binary file not shown.
Binary file added helpers/__pycache__/config.cpython-312.pyc
Binary file not shown.
3 changes: 2 additions & 1 deletion helpers/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def get_prompt(self, topic, relevant_data = None):
return response.text

def write_article(self, prompt):
response = self.model.generate_content("create a nice title for the article that would be generated by the following prompt\n" + prompt + "\n Just give the title alone, do not give the content")
response = self.model.generate_content("create a nice title for the article that would be generated by the following prompt\n" + prompt + "\n Just give the title alone, do not give the content, do not format the title.")
title = response.text
response = self.model.generate_content("create the article that would be generated by the following prompt\n" + prompt + "\n Just give the content alone, do not give the title. Write the content in a html code format and change styles as deemed necessary.")
content = response.text
Expand All @@ -27,4 +27,5 @@ def write_article(self, prompt):
tags = response.text
tags = tags.split(',')
print("article generated.")
content = content.replace("html", "", 1)
return {"title": title, "content": content, "tags": tags}
2 changes: 1 addition & 1 deletion helpers/blog.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def write_blog(title, content, tags):

payload = {
"title": title,
"contentFormat": "markdown",
"contentFormat": "html",
"content": content,
"canonicalUrl": "",
"tags": tags,
Expand Down
14 changes: 8 additions & 6 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>Submit Topic</title>
<title>Lazy Blog</title>
<style>
body {
font-family: Arial, sans-serif;
Expand Down Expand Up @@ -70,7 +70,9 @@
const result = await response.json();
document.getElementById('loading').style.display = 'none';
document.getElementById('result-container').style.display = 'block';
document.getElementById('result-content').innerText = result.res;
document.getElementById('result-title').innerText = result.title;
document.getElementById('result-content').innerHTML = result.content;
document.getElementById('result-tags').innerText = `Tags: ${result.tags.join(', ')}`;
}
</script>
</head>
Expand All @@ -84,13 +86,13 @@ <h1>Submit a Topic</h1>
</form>
</div>
<div class="loading" id="loading">Loading...</div>
<div class="container" id="result-container" style="display: none;">
<h1>Blog Written Successfully!</h1>
<p id="result-content"></p>
<div class="container" id="result-container" style="display: none; text-align: left;">
<h1 id="result-title"></h1>
<div id="result-content"></div>
<p id="result-tags" style="color: #007BFF; font-weight: bold;"></p>
<form action="/" method="get">
<button type="submit">Back to Form</button>
</form>
</div>
</body>
</html>

1 change: 1 addition & 0 deletions text.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"title": "The Marvelous Tapestry of the Animal Kingdom: Exploring Diversity, Adaptation, and Ecological Significance", "contentFormat": "html", "content": "<h1>The Wonders of the Animal Kingdom: Exploring Diversity, Adaptations, and Ecological Significance</h1>\n\n<p>The animal kingdom is a vast and diverse realm, encompassing an astonishing array of creatures that have evolved to inhabit every corner of our planet. From the smallest invertebrates to the largest mammals, animals exhibit remarkable adaptations and play crucial roles in maintaining the health and balance of our ecosystems.</p>\n\n<h2>Diversity of Animal Groups</h2>\n\n<ul>\n <li><b>Mammals:</b> Warm-blooded vertebrates characterized by fur, mammary glands, and live birth. Examples: humans, lions, whales.</li>\n <li><b>Birds:</b> Warm-blooded vertebrates with feathers, beaks, and wings for flight. Examples: eagles, penguins, hummingbirds.</li>\n <li><b>Reptiles:</b> Cold-blooded vertebrates with scales or plates on their skin. Examples: snakes, lizards, crocodiles.</li>\n li><b>Amphibians:</b> Cold-blooded vertebrates that spend part of their lives in water and part on land. Examples: frogs, salamanders, newts.</li>\n <li><b>Fish:</b> Cold-blooded vertebrates that live in water and use gills for breathing. Examples: sharks, tuna, goldfish.</li>\n <li><b>Invertebrates:</b> A vast group of animals that lack a backbone. Examples: insects, spiders, jellyfish, worms.</li>\n</ul>\n\n<h2>Adaptations to Diverse Environments</h2>\n\n<p>Animals have evolved a wide range of adaptations to survive in their specific environments:</p>\n\n<ul>\n <li><b>Camouflage:</b> Animals like chameleons and moths can change their color or shape to blend in with their surroundings.</li>\n <li><b>Crypsis:</b> Animals like stick insects and leaf frogs resemble objects in their environment for protection.</li>\n <li><b>Mimicry:</b> Some animals, such as fireflies, mimic the appearance or behavior of other animals to deter predators.</li>\n <li><b>Symbiosis:</b> Animals often form mutually beneficial partnerships with other organisms, such as clownfish and sea anemones.</li>\n</ul>\n\n<h2>Ecological Significance</h2>\n\n<p>Animals play vital roles in their ecosystems:</p>\n\n<ul>\n <li><b>Pollination:</b> Insects and birds help pollinate plants, ensuring reproduction and biodiversity.</li>\n <li><b>Seed dispersal:</b> Animals like birds and bats eat fruits and disperse their seeds, promoting plant growth.</li>\n <li><b>Nutrient recycling:</b> Decomposers, such as fungi and earthworms, break down organic matter, releasing nutrients into the soil.</li>\n <li><b>Predation:</b> Predators help control prey populations, maintaining ecosystem balance.</li>\n</ul>\n\n<h2>Importance of Animal Conservation</h2>\n\n<p>Animal conservation is essential for preserving the diversity and integrity of our planet:</p>\n\n<ul>\n <li><b>Biodiversity:</b> Animals are a vital part of the web of life, supporting countless other species.</li>\n <li><b>Ecosystem services:</b> Animals provide essential services that benefit humans, such as pollination, pest control, and water purification.</li>\n <li><b>Ethical considerations:</b> Animals are sentient beings that deserve our respect and protection.</li>\n</ul>\n\n<h2>Call to Action</h2>\n\n<p>The animal kingdom is a precious and irreplaceable part of our planet. It is our responsibility to treasure and protect these amazing creatures for future generations. We must:\n\n<ul>\n <li>Support organizations dedicated to animal conservation.</li>\n <li>Reduce our impact on the environment.</li>\n <li>Educate ourselves and others about the importance of animals.</li>\n</ul>\n\n<p>By working together, we can ensure that the wonders of the animal kingdom continue to enrich and inspire us for centuries to come.</p>", "canonicalUrl": "", "tags": ["Animal Kingdom", " Animal Diversity", " Animal Adaptations", " Ecological Significance", " Animal Conservation", " Biodiversity", " Ecosystem Services", " Animal Ethics", " Environmental Protection", " Conservation Education"], "publishStatus": "public"}

0 comments on commit a84d8ce

Please sign in to comment.