NASA APOD Explorer + AI Narrator (Gradio App with OpenAI)

A lightweight Gradio app that fetches NASA’s Astronomy Picture of the Day (APOD) and generates a concise, human-friendly narration using OpenAI. It supports HD images, date selection, graceful handling of videos, and clear error messages.

Big thanks to NASA for providing free access to their API.

What I Learned

I learned how to build a simple interactive UI using Gradio and connect it to Python functions. I also learned how to call external APIs, including NASA APOD and OpenAI, then combine their outputs to generate image explanations.

This project also helped me structure prompts and use the OpenAI chat completion API with system and user messages.

Project repository: AstronomyPictureExplorer on GitHub

AstronomyPictureExplorer.py

The app uses NASA’s APOD (Astronomy Picture of the Day) API to fetch the daily astronomy image. The get_nasa_apod() function retrieves the title, image URL, and explanation.

Next, the analyze_statement() function sends the image URL to OpenAI.

It uses the following prompt:

The following image is from NASA's Astronomy Picture of the Day.
Image URL: {image_url}
Create an explanation of the image in a way that is easy to understand and engaging.

The OpenAI call uses:

openai.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
        {"role": "system", "content": sytesmprompt},
        {"role": "user", "content": prompt},
    ],
)

This format, using system and user messages, is now the standard way to call OpenAI chat models.

Many other chat-focused LLM APIs, including Anthropic’s Claude and Google’s Gemini, follow a similar role and message structure.

For the UI, Gradio makes things very simple.

You provide:

  • The function name, app
  • The inputs array, including date and HD checkbox
  • The outputs array, including title, image, and explanation

Gradio automatically builds the UI, passes values into the function, and displays whatever the function returns. It is a great library for fast prototypes and POCs, and I will continue using it for future learning projects.

Share :

Related Posts

Chrome Extension: Political Bias Analyzer (Local LLAMA + OpenAI)

A Chrome extension that analyzes political bias in news articles and web content by extracting article content and providing a visual breakdown of left vs. right political leaning percentages. The ext

read more

Fine-Tuning GPT-2 on CFPB Dataset with ONNX and Gradio

What I LearnedWork with real-world datasets: Cleaning and preparing the CFPB dataset for model training. Dataset: [CFPB Consumer Finance Complaints](https://huggingface.co/datasets/CFPB

read more

Multi-Tool AI Agent - Document Processing with LLMs, TTS & Image Generation

An intelligent, multi-tool AI agent that automatically processes documents using LLMs, TTS, and image generation, all orchestrated through a SQLite database and a Gradio web interface. What I Lear

read more

RAG for Tabular Datasets

What I Learned My goal for this project was to deeply understand Retrieval-Augmented Generation (RAG) using a tabular dataset, moving beyond unstructured text use cases. I worked with a r

read more

Sales Update AI Assistant (Running on HuggingFace - Space)

Sales leaders often receive long narrative updates from team members through email or chat. These updates contain useful information, but they are often inconsistent, difficult to compare week to

read more