import osmnx as ox import matplotlib.pyplot as plt import tempfile import os def ambil_graf_dan_gambar(): # Nonaktifkan cache karena HuggingFace tidak izinkan write di luar tmp ox.settings.use_cache = False ox.settings.cache_folder = tempfile.gettempdir() ox.settings.logs_folder = tempfile.gettempdir() # Ambil graf OSM G = ox.graph_from_place("Keputih, Sukolilo, Surabaya, Indonesia", network_type="drive", simplify=True) # Buat plot dan simpan ke file fig, ax = ox.plot_graph(G, node_size=20, node_color='red', edge_color="gray", bgcolor="white", show=False, close=True) path_gambar = os.path.join(tempfile.gettempdir(), "graph_keputih_osm.png") fig.savefig(path_gambar, dpi=150) return G, path_gambar