Hey Hugging Face community! I’m new here, diving into Python and AI through Hugging Face’s awesome tools, and I’m excited to share a project idea I’m working on. As a road trip enthusiast, I want to build a simple fuel trip planner that uses a Hugging Face transformer model to parse natural language inputs (e.g., “I’m driving 500 km at 12 km/liter”) and output fuel cost estimates. I got inspired by a clean fuel calculator I found at kalkulatorpaliwa.com.pl, which handles inputs so smoothly, and I’d love to replicate that vibe with NLP.
Here’s a basic script using transformers
to extract trip details:
from transformers import pipeline
import re
def parse_trip_details(text):
nlp = pipeline("ner", model="dslim/bert-base-NER")
entities = nlp(text)
distance = None
efficiency = None
for entity in entities:
if "km" in entity["word"].lower():
distance = float(re.search(r"\d+", entity["word"]).group())
if "km/liter" in entity["word"].lower():
efficiency = float(re.search(r"\d+", entity["word"]).group())
if distance and efficiency:
fuel_needed = distance / efficiency
return {"distance": distance, "efficiency": efficiency, "fuel_needed": fuel_needed}
return {"error": "Couldn’t parse trip details"}
# Example
text = "I’m driving 500 km at 12 km/liter"
result = parse_trip_details(text)
print(result) # Outputs: {'distance': 500.0, 'efficiency': 12.0, 'fuel_needed': 41.666666666666664}
I’m aiming to add a fuel price input and calculate costs, maybe even suggest optimal routes. As a beginner, I’m struggling with a few things:
- Is
dslim/bert-base-NER
a good choice for extracting numbers and units, or is there a better model for this? - How can I improve the regex to handle varied inputs (e.g., “300 kilometers, 10 km per liter”)?
- Any tips for integrating this with a simple CLI or web interface?
I’d love to make it as user-friendly as kalkulatorpaliwa.com.pl. Any advice on model selection, text parsing, or cool features to add? Thanks for helping a newbie out!