File size: 1,184 Bytes
ddaad63
 
634a8f0
 
 
 
 
 
 
 
 
 
ddaad63
 
 
 
 
 
 
 
 
 
 
 
 
634a8f0
 
ddaad63
634a8f0
ddaad63
 
 
 
 
 
 
 
634a8f0
 
ddaad63
 
 
634a8f0
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# intent_parser.py - Extracts purpose and domain of the robotics app idea

import os
import google.generativeai as genai

# Use Gemini API Key from environment variable
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
if not GEMINI_API_KEY:
    raise EnvironmentError("GEMINI_API_KEY not set in environment variables.")

genai.configure(api_key=GEMINI_API_KEY)
model = genai.GenerativeModel("gemini-pro")

# Categories the system understands
INTENT_CATEGORIES = [
    "educational",
    "assistive",
    "entertainment",
    "industrial",
    "home automation",
    "healthcare",
    "retail",
    "creative"
]

# Classify robot idea using Gemini

def classify_robot_idea(user_input: str) -> str:
    prompt = f"""
    Classify this user idea into one of the following categories:
    {', '.join(INTENT_CATEGORIES)}.
    Only return the category word. If none fits, return 'creative'.

    Idea: {user_input}
    Category:
    """

    response = model.generate_content(prompt)
    return response.text.strip().lower()

# Example
if __name__ == "__main__":
    idea = "Build a robot that reminds elderly people to take medicine."
    print("Predicted Intent:", classify_robot_idea(idea))