Update app.py
Browse files
app.py
CHANGED
|
@@ -36,7 +36,7 @@ def call_gemini(prompt, api_key):
|
|
| 36 |
def get_species_links(species_name):
|
| 37 |
links = []
|
| 38 |
|
| 39 |
-
# GBIF
|
| 40 |
gbif_url = f"https://api.gbif.org/v1/species/match?name={species_name}"
|
| 41 |
r = requests.get(gbif_url).json()
|
| 42 |
|
|
@@ -46,8 +46,8 @@ def get_species_links(species_name):
|
|
| 46 |
# Wikipedia
|
| 47 |
links.append(f"https://en.wikipedia.org/wiki/{species_name.replace(' ', '_')}")
|
| 48 |
|
| 49 |
-
#
|
| 50 |
-
links.append(f"https://
|
| 51 |
|
| 52 |
return links
|
| 53 |
|
|
@@ -58,7 +58,7 @@ def get_species_links(species_name):
|
|
| 58 |
|
| 59 |
st.set_page_config(page_title="Biodiversity GIS Explorer", layout="wide")
|
| 60 |
st.title("π Biodiversity GIS Explorer")
|
| 61 |
-
st.write("GBIF + Gemini AI + Scientific Links +
|
| 62 |
|
| 63 |
# =========================
|
| 64 |
# INPUTS
|
|
@@ -114,9 +114,9 @@ Species Type: {species_type}
|
|
| 114 |
Species List:
|
| 115 |
{species_text}
|
| 116 |
|
| 117 |
-
1. Give a short biodiversity summary
|
| 118 |
-
2. Explain GIS mapping use cases
|
| 119 |
-
3. Give a beginner QGIS roadmap
|
| 120 |
"""
|
| 121 |
|
| 122 |
if GEMINI_API_KEY:
|
|
@@ -128,10 +128,10 @@ Species List:
|
|
| 128 |
st.write(ai_text)
|
| 129 |
|
| 130 |
# =========================
|
| 131 |
-
#
|
| 132 |
# =========================
|
| 133 |
|
| 134 |
-
st.subheader("π
|
| 135 |
|
| 136 |
all_links_text = ""
|
| 137 |
|
|
@@ -146,10 +146,10 @@ Species List:
|
|
| 146 |
all_links_text += f"\n{sp}:\n" + "\n".join(links) + "\n"
|
| 147 |
|
| 148 |
# =========================
|
| 149 |
-
|
| 150 |
-
|
| 151 |
|
| 152 |
-
|
| 153 |
BIODIVERSITY REPORT
|
| 154 |
|
| 155 |
Country: {country}
|
|
@@ -165,20 +165,22 @@ RESEARCH LINKS:
|
|
| 165 |
{all_links_text}
|
| 166 |
"""
|
| 167 |
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
|
|
|
|
|
|
|
|
|
| 171 |
|
| 172 |
-
|
| 173 |
-
pdf.multi_cell(0, 10, line)
|
| 174 |
|
| 175 |
-
|
| 176 |
-
pdf.output(pdf_file)
|
| 177 |
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
|
|
|
|
|
| 36 |
def get_species_links(species_name):
|
| 37 |
links = []
|
| 38 |
|
| 39 |
+
# GBIF official page
|
| 40 |
gbif_url = f"https://api.gbif.org/v1/species/match?name={species_name}"
|
| 41 |
r = requests.get(gbif_url).json()
|
| 42 |
|
|
|
|
| 46 |
# Wikipedia
|
| 47 |
links.append(f"https://en.wikipedia.org/wiki/{species_name.replace(' ', '_')}")
|
| 48 |
|
| 49 |
+
# Google Scholar (REAL research results)
|
| 50 |
+
links.append(f"https://scholar.google.com/scholar?q={species_name}")
|
| 51 |
|
| 52 |
return links
|
| 53 |
|
|
|
|
| 58 |
|
| 59 |
st.set_page_config(page_title="Biodiversity GIS Explorer", layout="wide")
|
| 60 |
st.title("π Biodiversity GIS Explorer")
|
| 61 |
+
st.write("GBIF + Gemini AI + Scientific Links + PDF Export")
|
| 62 |
|
| 63 |
# =========================
|
| 64 |
# INPUTS
|
|
|
|
| 114 |
Species List:
|
| 115 |
{species_text}
|
| 116 |
|
| 117 |
+
1. Give a short biodiversity summary.
|
| 118 |
+
2. Explain GIS mapping use cases.
|
| 119 |
+
3. Give a beginner QGIS roadmap.
|
| 120 |
"""
|
| 121 |
|
| 122 |
if GEMINI_API_KEY:
|
|
|
|
| 128 |
st.write(ai_text)
|
| 129 |
|
| 130 |
# =========================
|
| 131 |
+
# SCIENTIFIC LINKS
|
| 132 |
# =========================
|
| 133 |
|
| 134 |
+
st.subheader("π Research Links")
|
| 135 |
|
| 136 |
all_links_text = ""
|
| 137 |
|
|
|
|
| 146 |
all_links_text += f"\n{sp}:\n" + "\n".join(links) + "\n"
|
| 147 |
|
| 148 |
# =========================
|
| 149 |
+
# PDF EXPORT
|
| 150 |
+
# =========================
|
| 151 |
|
| 152 |
+
final_text = f"""
|
| 153 |
BIODIVERSITY REPORT
|
| 154 |
|
| 155 |
Country: {country}
|
|
|
|
| 165 |
{all_links_text}
|
| 166 |
"""
|
| 167 |
|
| 168 |
+
pdf = FPDF()
|
| 169 |
+
pdf.add_page()
|
| 170 |
+
pdf.set_font("Arial", size=12)
|
| 171 |
+
|
| 172 |
+
for line in final_text.split("\n"):
|
| 173 |
+
pdf.multi_cell(0, 10, line)
|
| 174 |
|
| 175 |
+
pdf_file = "biodiversity_report.pdf"
|
|
|
|
| 176 |
|
| 177 |
+
pdf.output(pdf_file)
|
|
|
|
| 178 |
|
| 179 |
+
with open(pdf_file, "rb") as f:
|
| 180 |
+
st.download_button(
|
| 181 |
+
label="π Download PDF Report",
|
| 182 |
+
data=f,
|
| 183 |
+
file_name="biodiversity_report.pdf",
|
| 184 |
+
mime="application/pdf"
|
| 185 |
+
)
|
| 186 |
+
|