<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Preetkamal Singh</title>
    <description>The latest articles on DEV Community by Preetkamal Singh (@preetkamal_singh_a2fe7281).</description>
    <link>https://dev.to/preetkamal_singh_a2fe7281</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2313493%2F57f4b1fe-f9b4-4b38-b1e6-c0cc357e91fb.png</url>
      <title>DEV Community: Preetkamal Singh</title>
      <link>https://dev.to/preetkamal_singh_a2fe7281</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/preetkamal_singh_a2fe7281"/>
    <language>en</language>
    <item>
      <title>City Simulation with LLMs — Predicting Traffic &amp; Generating Natural-Language Reports</title>
      <dc:creator>Preetkamal Singh</dc:creator>
      <pubDate>Wed, 17 Sep 2025 08:42:10 +0000</pubDate>
      <link>https://dev.to/preetkamal_singh_a2fe7281/city-simulation-with-llms-predicting-traffic-generating-natural-language-3f4d</link>
      <guid>https://dev.to/preetkamal_singh_a2fe7281/city-simulation-with-llms-predicting-traffic-generating-natural-language-3f4d</guid>
      <description>&lt;p&gt;&lt;strong&gt;TL;DR:&lt;/strong&gt; I built a city traffic simulation that ingests sensor data, predicts congestion, and uses an LLM to produce human-readable incident reports.  &lt;/p&gt;

&lt;p&gt;Live demo:&lt;a href="https://vercel.com/kamalpannus-projects/trafficpredictorfrontend" rel="noopener noreferrer"&gt;https://vercel.com/kamalpannus-projects/trafficpredictorfrontend&lt;/a&gt;  | Code: &lt;a href="https://github.com/Kamalpannu/trafficPredictor-Backend" rel="noopener noreferrer"&gt;https://github.com/Kamalpannu/trafficPredictor-Backend&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/Kamalpannu/trafficpredictorfrontend" rel="noopener noreferrer"&gt;https://github.com/Kamalpannu/trafficpredictorfrontend&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;City operations teams need quick summaries of traffic hotspots from noisy sensor streams. Raw numbers are hard to scan under time pressure — so I built a system that predicts traffic issues and auto-generates plain-English reports.&lt;/p&gt;

&lt;h2&gt;
  
  
  Architecture
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Data ingestion:&lt;/strong&gt; simulated traffic sensors → time series store
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prediction service:&lt;/strong&gt; Python model (simple regression + heuristic)
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;LLM service:&lt;/strong&gt; LangChain wrapping an LLM to summarize predictions into reports
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Frontend:&lt;/strong&gt; React app for dashboards and report viewer
&lt;/li&gt;
&lt;li&gt;Dockerized and deployed via CI/CD&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Key implementation
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
python
from fastapi import FastAPI
from pydantic import BaseModel
from langchain import OpenAI, LLMChain, PromptTemplate

app = FastAPI()
llm = OpenAI(api_key="YOUR_KEY", temperature=0.2)
prompt = PromptTemplate(
    input_variables=["summary"],
    template="You are a city ops assistant. Given this summary: {summary}\nWrite a 3-sentence incident report with suggested actions."
)
chain = LLMChain(llm=llm, prompt=prompt)

class Payload(BaseModel):
    summary: str

@app.post("/report")
async def report(payload: Payload):
    text = chain.run(payload.summary)
    return {"report": text}

Note: replace YOUR_KEY with your environment variable or secrets management.

What I learned

LLMs are great at turning numeric summaries into useful prose, but they require clear prompts and guardrails.

Keep the LLM step after deterministic prediction — don’t let it invent numbers.

Results

Generated concise reports that a non-technical operator can act on.

Demo and sample reports: see https://github.com/Kamalpannu/trafficPredictor-Backend
https://github.com/Kamalpannu/trafficpredictorfrontend

Full source code and deployment steps: https://vercel.com/kamalpannus-projects/trafficpredictorfrontend
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>ai</category>
      <category>langchain</category>
      <category>fastapi</category>
      <category>python</category>
    </item>
  </channel>
</rss>
