Skip to content

A curated collection of practical AI projects implementing OCR systems, RAG, AI agents, and other AI use cases.

fix(multimodal_weather_app): remove unresolved merge conflict markers

Rudy Celekli5468dd430997
diff --git a/multimodal/multimodal_weather_app/.env.example b/multimodal/multimodal_weather_app/.env.example
index 3f60270..9c47f26 100644
--- a/multimodal/multimodal_weather_app/.env.example
+++ b/multimodal/multimodal_weather_app/.env.example
@@ -1,6 +1,3 @@
-<<<<<<< HEAD
-=======
# Mistral AI API key (required)
# Get your free key at https://platform.mistral.ai
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
MISTRAL_API_KEY=your_mistral_api_key_here
diff --git a/multimodal/multimodal_weather_app/app.py b/multimodal/multimodal_weather_app/app.py
index c36077a..3a7ff5c 100644
--- a/multimodal/multimodal_weather_app/app.py
+++ b/multimodal/multimodal_weather_app/app.py
@@ -1,15 +1,9 @@
-<<<<<<< HEAD
-import os
-import base64
-import asyncio
-=======
"""Multimodal weather app that uses Mistral Small vision to identify a city from a map image, then fetches live weather via native tool calling."""
import os
import base64
import asyncio
import logging
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
import tempfile
import threading
import gradio as gr
@@ -22,19 +16,13 @@ from langchain_core.messages import HumanMessage
load_dotenv()
MISTRAL_API_KEY = os.getenv("MISTRAL_API_KEY")
-<<<<<<< HEAD
-=======
logger = logging.getLogger(__name__)
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
# ── Image helpers ────────────────────────────────────────────────────────────
def image_to_base64(image: Image.Image) -> str:
-<<<<<<< HEAD
-=======
"""Convert a PIL image to a base64-encoded JPEG string for use in API requests."""
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
# Write to a real temp file first to ensure a complete, valid JPEG on disk
with tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) as tmp:
tmp_path = tmp.name
@@ -42,21 +30,14 @@ def image_to_base64(image: Image.Image) -> str:
with open(tmp_path, "rb") as f:
b64 = base64.b64encode(f.read()).decode("utf-8")
os.remove(tmp_path)
-<<<<<<< HEAD
- print(f"[base64 preview]: {b64[:100]!r} (total length: {len(b64)})")
-=======
logger.debug("[base64 preview]: %r (total length: %d)", b64[:100], len(b64))
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
return b64
# ── City identification via Mistral Small (vision) ───────────────────────────
def identify_city(image: Image.Image) -> str:
-<<<<<<< HEAD
-=======
"""Use Mistral Small vision to read a map image and return the identified city name."""
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
b64 = image_to_base64(image)
llm = ChatMistralAI(model="mistral-small-latest", api_key=MISTRAL_API_KEY)
message = HumanMessage(content=[
@@ -65,11 +46,7 @@ def identify_city(image: Image.Image) -> str:
])
response = llm.invoke([message])
raw = response.content.strip()
-<<<<<<< HEAD
- print(f"[mistral vision identified city]: {raw!r}")
-=======
logger.debug("[mistral vision identified city]: %r", raw)
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
return raw
@@ -151,10 +128,7 @@ _WEATHER_TOOL_SCHEMA = {
def call_weather_tool(city: str) -> str:
-<<<<<<< HEAD
-=======
"""Ask Mistral Small to invoke the weather tool for the given city and return the formatted result."""
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
llm = ChatMistralAI(model="mistral-small-latest", api_key=MISTRAL_API_KEY)
llm_with_tools = llm.bind_tools([_WEATHER_TOOL_SCHEMA])
response = llm_with_tools.invoke([HumanMessage(content=f"Get the current weather for {city}.")])
@@ -167,10 +141,7 @@ def call_weather_tool(city: str) -> str:
# ── Output parser ─────────────────────────────────────────────────────────────
def parse_weather(text: str) -> tuple:
-<<<<<<< HEAD
-=======
"""Extract temperature, conditions, humidity, and wind speed from a formatted weather string."""
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
temp = conditions = humidity = wind = ""
for line in text.splitlines():
if "Temperature:" in line:
@@ -187,10 +158,7 @@ def parse_weather(text: str) -> tuple:
# ── Main pipeline ─────────────────────────────────────────────────────────────
def analyze(image):
-<<<<<<< HEAD
-=======
"""Run the full pipeline: identify the city from the uploaded map image, then fetch and return live weather data."""
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
if image is None:
return "Please upload a map image.", "", "", "", ""