Spaces:
Sleeping
Sleeping
Download app.py from Bora9/BoraPalyAI: direct link, hf CLI and curl.
- Browser
- Download file 21.3 kB
-
https://huggingface.co/spaces/Bora9/BoraPalyAI/resolve/main/app.py
- Command line
-
hf download hf://spaces/Bora9/BoraPalyAI/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Bora9/BoraPalyAI/resolve/main/app.py
21.3 kB
| import gradio as gr | |
| import folium | |
| import pandas as pd | |
| import html | |
| # --------------------------------------------------------------------------- | |
| # DATA DEFINITIONS | |
| # --------------------------------------------------------------------------- | |
| PERIOD_COLORS = { | |
| "Cambrian": "#7FA080", | |
| "Ordovician": "#00A88D", | |
| "Silurian": "#B3E1B6", | |
| "Devonian": "#CB8C37", | |
| "Carboniferous": "#67A5A5", | |
| "Permian": "#F04028", | |
| "Triassic": "#812990", | |
| "Jurassic": "#3492C7", | |
| "Cretaceous": "#8CBA22", | |
| "Paleogene": "#FD9A52", | |
| "Neogene": "#FFE619", | |
| "Quaternary": "#FFF2AE" | |
| } | |
| OIL_GAS_ZONES = [ | |
| { | |
| "name": "Southeast Anatolia Petroleum Province", | |
| "basin_name": "Southeastern Anatolia Basin", | |
| "center_lat": 37.5, | |
| "center_lng": 40.5, | |
| "source_rocks": ["Derdere Fm (Cretaceous)", "Karababa Fm (Cretaceous)", "Silurian shales"], | |
| "reservoir_rocks": ["Mardin Group carbonates", "Midyat Fm", "Cretaceous carbonates"], | |
| "key_biozones": ["Globotruncana arca Zone", "Orbitoides media Zone", "Nummulites perforatus Zone"], | |
| "palynological_markers": ["Normapolles complex", "Oligosphaeridium complex", "Areoligera senonensis"], | |
| "potential_rating": "proven", | |
| "toc_range": "1-5%", | |
| "kerogen_type": "Type II", | |
| "maturity_window": "Oil to wet gas", | |
| "description": "Major proven petroleum province with active production. Cretaceous source rocks with carbonate reservoirs." | |
| }, | |
| { | |
| "name": "Thrace Basin Gas Province", | |
| "basin_name": "Thrace Basin", | |
| "center_lat": 41.5, | |
| "center_lng": 27.5, | |
| "source_rocks": ["Hamitabat Fm (Eocene)", "Ceylan Fm (Oligocene)"], | |
| "reservoir_rocks": ["Hamitabat sandstones", "Osmancık sandstones", "Mezardere turbidites"], | |
| "key_biozones": ["Globigerina ampliapertura Zone", "Nummulites Zone"], | |
| "palynological_markers": ["Apectodinium augustum", "Homotryblium tenuispinosum", "Impagidinium"], | |
| "potential_rating": "proven", | |
| "toc_range": "0.5-2%", | |
| "kerogen_type": "Type III", | |
| "maturity_window": "Dry gas", | |
| "description": "Principal gas-producing basin of Türkiye. Eocene-Oligocene marine source rocks with deltaic reservoir sandstones." | |
| }, | |
| { | |
| "name": "İskenderun Basin", | |
| "basin_name": "İskenderun-Latakia Basin", | |
| "center_lat": 36.5, | |
| "center_lng": 36.2, | |
| "source_rocks": ["Cretaceous organic marls", "Paleogene shales"], | |
| "reservoir_rocks": ["Mesozoic carbonates", "Miocene clastics"], | |
| "key_biozones": ["Globotruncana Zone", "Orbitolina Zone"], | |
| "palynological_markers": ["Subtilisphaera", "Hystrichosphaeridium", "Cyclonephelium"], | |
| "potential_rating": "high", | |
| "toc_range": "1-2.5%", | |
| "kerogen_type": "Type II", | |
| "maturity_window": "Oil window", | |
| "description": "Extension of proven Eastern Mediterranean petroleum system. Mesozoic source rocks in pull-apart basin." | |
| }, | |
| { | |
| "name": "Adana-Cilicia Basin", | |
| "basin_name": "Adana Basin", | |
| "center_lat": 37.0, | |
| "center_lng": 35.3, | |
| "source_rocks": ["Kuzgun Fm (Miocene)", "Cretaceous marls"], | |
| "reservoir_rocks": ["Karaisalı Fm carbonates", "Handere sandstones", "Cretaceous reefs"], | |
| "key_biozones": ["Orbulina universa Zone", "Globorotalia mayeri Zone"], | |
| "palynological_markers": ["Spiniferites ramosus", "Operculodinium centrocarpum", "Lingulodinium machaerophorum"], | |
| "potential_rating": "moderate", | |
| "toc_range": "0.5-2%", | |
| "kerogen_type": "Type II/III", | |
| "maturity_window": "Oil window", | |
| "description": "Neogene fore-arc basin with marine source rocks and structural/stratigraphic traps." | |
| }, | |
| { | |
| "name": "Zonguldak Coal Basin HC Potential", | |
| "basin_name": "Western Black Sea", | |
| "center_lat": 41.4, | |
| "center_lng": 32.0, | |
| "source_rocks": ["Kozlu Fm coals (Carboniferous)", "Alacaagzi Fm shales"], | |
| "reservoir_rocks": ["Carboniferous sandstones", "Fractured coals"], | |
| "key_biozones": ["Neuropteris Zone", "Lycospora pusilla Zone"], | |
| "palynological_markers": ["Lycospora pusilla", "Florinites mediapudens", "Densosporites"], | |
| "potential_rating": "moderate", | |
| "toc_range": "5-60%", | |
| "kerogen_type": "Type III", | |
| "maturity_window": "Gas to overmature", | |
| "description": "Coal-bed methane and conventional gas potential. Carboniferous coal measures as source and unconventional reservoir." | |
| }, | |
| { | |
| "name": "Sivas Basin Potential", | |
| "basin_name": "Sivas Basin", | |
| "center_lat": 39.6, | |
| "center_lng": 37.2, | |
| "source_rocks": ["Eocene marls", "Oligocene lacustrine shales"], | |
| "reservoir_rocks": ["Oligocene sandstones", "Fractured carbonates"], | |
| "key_biozones": ["Nummulites Zone", "Alveolina Zone"], | |
| "palynological_markers": ["Homotryblium", "Wetzeliella", "Deflandrea"], | |
| "potential_rating": "moderate", | |
| "toc_range": "1-3%", | |
| "kerogen_type": "Type II", | |
| "maturity_window": "Oil window", | |
| "description": "Foreland basin with proven shows. Eocene-Oligocene source rocks with evaporite seals." | |
| } | |
| ] | |
| FOSSIL_LOCALITIES = [ | |
| { | |
| "name": "Haymana Basin - Ankara", | |
| "latitude": 39.43, | |
| "longitude": 32.50, | |
| "geological_period": "Paleogene", | |
| "fossil_types": ["Foraminifera", "Mollusks"], | |
| "formation_name": "Haymana Formation", | |
| "age_mya": "66-48 Ma", | |
| "index_fossils": ["Nummulites", "Alveolina"], | |
| "palynomorphs": ["Spiniferites", "Apectodinium"], | |
| "hydrocarbon_potential": "moderate", | |
| "source_rock_quality": "Marine shales, TOC 1-2%", | |
| "depositional_environment": "Deep marine turbidites", | |
| "correlation_units": ["Tethyan foreland basins"], | |
| "references": "Görür et al., 1998, Basin Research", | |
| "description": "Paleocene-Eocene deep marine turbidites showing active foreland basin evolution." | |
| }, | |
| { | |
| "name": "Eskipazar Formation - Karabuk", | |
| "latitude": 40.95, | |
| "longitude": 32.53, | |
| "geological_period": "Carboniferous", | |
| "fossil_types": ["Plants", "Brachiopods"], | |
| "formation_name": "Eskipazar Formation", | |
| "age_mya": "318-299 Ma", | |
| "index_fossils": ["Neuropteris", "Pecopteris"], | |
| "palynomorphs": ["Lycospora", "Vestispora"], | |
| "hydrocarbon_potential": "high", | |
| "source_rock_quality": "Coal seams, gas-prone", | |
| "thermal_maturity": "High volatile bituminous", | |
| "depositional_environment": "Coastal swamp", | |
| "correlation_units": ["Westphalian coal measures"], | |
| "references": "Kerey et al., 2004, Turkish Journal of Earth Sciences", | |
| "description": "Upper Carboniferous coal-bearing sequence with significant coal-bed gas potential." | |
| }, | |
| { | |
| "name": "Cudi Mountains - Sirnak", | |
| "latitude": 37.35, | |
| "longitude": 42.62, | |
| "geological_period": "Cretaceous", | |
| "fossil_types": ["Foraminifera", "Rudists"], | |
| "formation_name": "Cudi Group", | |
| "age_mya": "145-66 Ma", | |
| "index_fossils": ["Orbitolina", "Orbitoides"], | |
| "palynomorphs": ["Normapolles", "Odontochitina"], | |
| "hydrocarbon_potential": "high", | |
| "source_rock_quality": "Reservoir and source rocks", | |
| "depositional_environment": "Carbonate platform", | |
| "correlation_units": ["Arabian Platform"], | |
| "references": "Yılmaz et al., 2014, Marine and Petroleum Geology", | |
| "description": "Crucial Cretaceous carbonate platform section along the Arabian platform margin." | |
| }, | |
| { | |
| "name": "Sakarkaya Limestone - Bursa", | |
| "latitude": 40.18, | |
| "longitude": 29.07, | |
| "geological_period": "Silurian", | |
| "fossil_types": ["Graptolites", "Brachiopods"], | |
| "formation_name": "Sakarkaya Limestone", | |
| "age_mya": "443-419 Ma", | |
| "index_fossils": ["Monograptus", "Cyrtograptus"], | |
| "palynomorphs": ["Eisenackitina"], | |
| "hydrocarbon_potential": "low", | |
| "depositional_environment": "Shallow marine shelf", | |
| "correlation_units": ["Wenlock Limestone"], | |
| "references": "Göncüoğlu, 1997, Geologische Rundschau", | |
| "description": "Silurian shallow marine carbonates representing early Palaeozoic Istanbul terrane sequences." | |
| }, | |
| { | |
| "name": "Tepeler Formation - Bursa", | |
| "latitude": 40.18, | |
| "longitude": 29.36, | |
| "geological_period": "Triassic", | |
| "fossil_types": ["Ammonites", "Bivalves"], | |
| "formation_name": "Tepeler Formation", | |
| "age_mya": "242-201 Ma", | |
| "index_fossils": ["Daonella", "Halobia"], | |
| "palynomorphs": ["Ovalipollis"], | |
| "hydrocarbon_potential": "low", | |
| "depositional_environment": "Pelagic basin", | |
| "correlation_units": ["Hallstatt facies"], | |
| "references": "Okay et al., 1991, Tectonics", | |
| "description": "Middle-Upper Triassic pelagic carbonates within the Sakarya Zone." | |
| }, | |
| { | |
| "name": "Cubuk Formation - Ankara", | |
| "latitude": 40.22, | |
| "longitude": 33.00, | |
| "geological_period": "Jurassic", | |
| "fossil_types": ["Ammonites", "Brachiopods"], | |
| "formation_name": "Çubuk Formation", | |
| "age_mya": "201-163 Ma", | |
| "index_fossils": ["Harpoceras", "Leioceras"], | |
| "palynomorphs": ["Classopollis"], | |
| "hydrocarbon_potential": "low", | |
| "depositional_environment": "Shallow marine shelf", | |
| "correlation_units": ["Tethyan Jurassic"], | |
| "references": "Göncüoğlu et al., 1992, Turkish Journal of Earth Sciences", | |
| "description": "Lower-Middle Jurassic shallow marine sequences yielding rich ammonite biozones." | |
| }, | |
| { | |
| "name": "Cataltepe Formation - Ankara", | |
| "latitude": 40.10, | |
| "longitude": 32.85, | |
| "geological_period": "Cambrian", | |
| "fossil_types": ["Trilobites"], | |
| "formation_name": "Çaltepe Formation", | |
| "age_mya": "510-500 Ma", | |
| "index_fossils": ["Paradoxides", "Conocoryphe"], | |
| "palynomorphs": ["Skiagia"], | |
| "hydrocarbon_potential": "none", | |
| "depositional_environment": "Shallow marine shelf", | |
| "correlation_units": ["Tethyan Cambrian"], | |
| "references": "Dean et al., 1997, Geological Magazine", | |
| "description": "Middle Cambrian shallow marine limestones containing diagnostic Tethyan trilobite fauna." | |
| }, | |
| { | |
| "name": "Yoncali Formation - Denizli", | |
| "latitude": 37.95, | |
| "longitude": 29.08, | |
| "geological_period": "Neogene", | |
| "fossil_types": ["Mammals", "Mollusks"], | |
| "formation_name": "Yoncalı Formation", | |
| "age_mya": "8-2.6 Ma", | |
| "index_fossils": ["Hipparion", "Gazella"], | |
| "palynomorphs": ["Quercoidites"], | |
| "hydrocarbon_potential": "none", | |
| "depositional_environment": "Lacustrine-alluvial", | |
| "correlation_units": ["Aegean Neogene basins"], | |
| "references": "Alcıçek et al., 2005, Sedimentary Geology", | |
| "description": "Late Miocene-Pliocene terrestrial sequence providing key vertebrate mammal fauna calibrations." | |
| } | |
| ] | |
| # Simulated User Submissions database | |
| user_submissions = [] | |
| # --------------------------------------------------------------------------- | |
| # MAP RENDERING FUNCTION | |
| # --------------------------------------------------------------------------- | |
| def generate_scholar_link(ref_text): | |
| query = html.escape(ref_text) | |
| return f"https://scholar.google.com/scholar?q={query}" | |
| def build_map(period_filter, potential_filter, search_query): | |
| # Center map on Türkiye encompassing seas (Black, Mediterranean, Aegean) | |
| m = folium.Map( | |
| location=[39.0, 35.2], | |
| zoom_start=6, | |
| tiles="CartoDB positron", | |
| control_scale=True | |
| ) | |
| # Base layers | |
| folium.TileLayer("OpenStreetMap", name="Street Map").add_to(m) | |
| folium.TileLayer("Esri WorldImagery", name="Satellite").add_to(m) | |
| # Feature groups | |
| fossil_group = folium.FeatureGroup(name="Fossil Localities", show=True) | |
| petroleum_group = folium.FeatureGroup(name="Oil & Gas Potential Zones", show=True) | |
| # Render Oil & Gas Zones | |
| for zone in OIL_GAS_ZONES: | |
| if potential_filter != "All" and zone["potential_rating"].lower() != potential_filter.lower(): | |
| continue | |
| if search_query and search_query.lower() not in zone["name"].lower() and search_query.lower() not in zone["basin_name"].lower(): | |
| continue | |
| color = "#e74c3c" if zone["potential_rating"] == "proven" else "#f39c12" if zone["potential_rating"] == "high" else "#3498db" | |
| popup_html = f""" | |
| <div style="font-family: Arial, sans-serif; min-width: 260px;"> | |
| <h4 style="margin:0 0 5px 0; color:#2c3e50;">🛢️ {zone['name']}</h4> | |
| <p style="margin:2px 0;"><b>Basin:</b> {zone['basin_name']}</p> | |
| <p style="margin:2px 0;"><b>Potential:</b> <span style="text-transform:uppercase; font-weight:bold; color:{color};">{zone['potential_rating']}</span></p> | |
| <p style="margin:2px 0;"><b>TOC:</b> {zone['toc_range']} | <b>Kerogen:</b> {zone['kerogen_type']}</p> | |
| <p style="margin:2px 0;"><b>Maturity:</b> {zone['maturity_window']}</p> | |
| <hr style="margin:6px 0;"> | |
| <p style="margin:2px 0;"><b>Source Rocks:</b> {', '.join(zone['source_rocks'])}</p> | |
| <p style="margin:2px 0;"><b>Reservoirs:</b> {', '.join(zone['reservoir_rocks'])}</p> | |
| <p style="margin:2px 0;"><b>Palynology:</b> {', '.join(zone['palynological_markers'])}</p> | |
| <p style="margin:6px 0 0 0; font-size:0.85em; color:#555;">{zone['description']}</p> | |
| </div> | |
| """ | |
| folium.CircleMarker( | |
| location=[zone["center_lat"], zone["center_lng"]], | |
| radius=12, | |
| color=color, | |
| fill=True, | |
| fill_color=color, | |
| fill_opacity=0.4, | |
| popup=folium.Popup(popup_html, max_width=320), | |
| tooltip=f"Oil/Gas Zone: {zone['name']}" | |
| ).add_to(petroleum_group) | |
| # Render Fossils | |
| for loc in FOSSIL_LOCALITIES: | |
| if period_filter != "All" and loc["geological_period"] != period_filter: | |
| continue | |
| if potential_filter != "All" and loc.get("hydrocarbon_potential", "").lower() != potential_filter.lower(): | |
| continue | |
| if search_query: | |
| sq = search_query.lower() | |
| match = (sq in loc["name"].lower() or | |
| sq in loc["formation_name"].lower() or | |
| any(sq in f.lower() for f in loc["fossil_types"])) | |
| if not match: | |
| continue | |
| color = PERIOD_COLORS.get(loc["geological_period"], "#7f8c8d") | |
| scholar_url = generate_scholar_link(loc["references"]) | |
| popup_html = f""" | |
| <div style="font-family: Arial, sans-serif; min-width: 250px;"> | |
| <h4 style="margin:0 0 5px 0; color:#2c3e50;">🦴 {loc['name']}</h4> | |
| <p style="margin:2px 0;"><b>Formation:</b> {loc['formation_name']} ({loc['age_mya']})</p> | |
| <p style="margin:2px 0;"><b>Period:</b> <span style="background:{color}; padding:2px 6px; border-radius:3px; color:#000; font-weight:bold;">{loc['geological_period']}</span></p> | |
| <p style="margin:2px 0;"><b>Fossil Types:</b> {', '.join(loc['fossil_types'])}</p> | |
| <p style="margin:2px 0;"><b>Index Fossils:</b> {', '.join(loc.get('index_fossils', []))}</p> | |
| <p style="margin:2px 0;"><b>Palynomorphs:</b> {', '.join(loc.get('palynomorphs', ['N/A']))}</p> | |
| <p style="margin:2px 0;"><b>HC Potential:</b> {loc.get('hydrocarbon_potential', 'N/A').upper()}</p> | |
| <hr style="margin:6px 0;"> | |
| <p style="margin:2px 0; font-size:0.9em;"><b>Reference:</b> <a href="{scholar_url}" target="_blank" style="color:#2980b9;">{loc['references']} 🔗</a></p> | |
| </div> | |
| """ | |
| folium.CircleMarker( | |
| location=[loc["latitude"], loc["longitude"]], | |
| radius=7, | |
| color="#2c3e50", | |
| weight=1, | |
| fill=True, | |
| fill_color=color, | |
| fill_opacity=0.85, | |
| popup=folium.Popup(popup_html, max_width=300), | |
| tooltip=f"{loc['name']} ({loc['geological_period']})" | |
| ).add_to(fossil_group) | |
| fossil_group.add_to(m) | |
| petroleum_group.add_to(m) | |
| folium.LayerControl().add_to(m) | |
| return m._repr_html_() | |
| # --------------------------------------------------------------------------- | |
| # SUBMISSION WORKFLOW | |
| # --------------------------------------------------------------------------- | |
| def submit_locality(name, lat, lng, period, fossils, formation, ref, h_pot): | |
| new_entry = { | |
| "name": name, | |
| "latitude": float(lat), | |
| "longitude": float(lng), | |
| "geological_period": period, | |
| "fossil_types": [f.strip() for f in fossils.split(",")], | |
| "formation_name": formation, | |
| "references": ref, | |
| "hydrocarbon_potential": h_pot, | |
| "status": "Pending Moderation" | |
| } | |
| user_submissions.append(new_entry) | |
| return f"✅ Locality '{name}' successfully submitted for Eurasia Natural History Association review!" | |
| # --------------------------------------------------------------------------- | |
| # GRADIO INTERFACE | |
| # --------------------------------------------------------------------------- | |
| custom_css = """ | |
| .container { max-width: 1200px; margin: auto; } | |
| .header-box { text-align: center; padding: 20px; background: linear-gradient(135deg, #1e3c72, #2a5298); color: white; border-radius: 8px; margin-bottom: 15px; } | |
| """ | |
| with gr.Blocks(css=custom_css, title="Türkiye Paleontological Map | ENHA") as demo: | |
| gr.HTML( | |
| """ | |
| <div class="header-box"> | |
| <h1>🏛️ Türkiye Paleontological & Petroleum Heritage Map</h1> | |
| <h3>Eurasia Natural History Association (ENHA) Scientific Platform</h3> | |
| <p>Interactive biostratigraphy, fossil localities, palynology, and hydrocarbon source rock potential map across Türkiye and surrounding basins.</p> | |
| </div> | |
| """ | |
| ) | |
| with gr.Tabs(): | |
| with gr.Tab("Interactive Geospatial Map"): | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| gr.Markdown("### 🔍 Filters & Search") | |
| period_dropdown = gr.Dropdown( | |
| choices=["All"] + list(PERIOD_COLORS.keys()), | |
| value="All", | |
| label="Geological Period" | |
| ) | |
| potential_dropdown = gr.Dropdown( | |
| choices=["All", "proven", "high", "moderate", "low", "none"], | |
| value="All", | |
| label="Hydrocarbon Potential" | |
| ) | |
| search_input = gr.Textbox( | |
| placeholder="Search formation, fossil, or basin...", | |
| label="Keyword Search" | |
| ) | |
| filter_btn = gr.Button("Apply Filters", variant="primary") | |
| gr.Markdown("### 🎨 Geological Legend") | |
| legend_html = "<div style='display:grid; grid-template-columns: 1fr 1fr; gap:4px; font-size:0.85em;'>" | |
| for p, col in PERIOD_COLORS.items(): | |
| legend_html += f"<div><span style='background:{col}; padding:2px 8px; border-radius:3px;'></span> {p}</div>" | |
| legend_html += "</div>" | |
| gr.HTML(legend_html) | |
| with gr.Column(scale=3): | |
| map_output = gr.HTML(value=build_map("All", "All", "")) | |
| filter_btn.click( | |
| fn=build_map, | |
| inputs=[period_dropdown, potential_dropdown, search_input], | |
| outputs=map_output | |
| ) | |
| with gr.Tab("Suggest New Locality / Data"): | |
| gr.Markdown("### 📝 Submit User Suggestion for ENHA Moderation") | |
| with gr.Row(): | |
| sub_name = gr.Textbox(label="Locality / Site Name") | |
| sub_period = gr.Dropdown(choices=list(PERIOD_COLORS.keys()), label="Geological Period") | |
| with gr.Row(): | |
| sub_lat = gr.Number(label="Latitude (e.g. 39.5)", value=39.0) | |
| sub_lng = gr.Number(label="Longitude (e.g. 32.5)", value=35.0) | |
| with gr.Row(): | |
| sub_formation = gr.Textbox(label="Formation Name") | |
| sub_fossils = gr.Textbox(label="Fossil Types (comma separated)") | |
| with gr.Row(): | |
| sub_hpot = gr.Dropdown(choices=["proven", "high", "moderate", "low", "none"], value="moderate", label="HC Potential") | |
| sub_ref = gr.Textbox(label="Publication Reference") | |
| sub_btn = gr.Button("Submit for Review", variant="primary") | |
| sub_output = gr.Textbox(label="Submission Status", interactive=False) | |
| sub_btn.click( | |
| fn=submit_locality, | |
| inputs=[sub_name, sub_lat, sub_lng, sub_period, sub_fossils, sub_formation, sub_ref, sub_hpot], | |
| outputs=sub_output | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |