File size: 3,311 Bytes
422efbb
 
 
 
3d45838
422efbb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import google.generativeai as genai
import gradio as gr

# Your API key (replace with a new one if this doesn't work)
GOOGLE_API_KEY = "AIzaSyAVnkLjvUEZaQA5a-oUxcxb3bZ5amZDYqM"  

# Configure API
genai.configure(api_key=GOOGLE_API_KEY)

# Use the free model
model = genai.GenerativeModel('gemini-1.5-flash-latest')

def generate_recommendation(problem_type, dataset_size, num_features, feature_type, priority, additional_info):
    prompt = f"""
    You are an expert machine learning engineer specializing in algorithm selection.
    Recommend machine learning algorithms for a project with these characteristics:
    
    1. Problem Type: {problem_type}
    2. Dataset Size: {dataset_size}
    3. Number of Features: {num_features}
    4. Feature Types: {feature_type}
    5. Priority: {priority}
    6. Additional Information: {additional_info}
    
    Provide:
    1. Top 3 ranked algorithm recommendations (most suitable first)
    2. For each algorithm:
       - Brief justification
       - Strengths for this use case
       - Potential limitations
    3. Final recommendation with detailed comparison
    
    Format exactly like this:
    
    === TOP RECOMMENDATIONS ===
    1. [Algorithm 1]
    - Why: [Justification]
    - Pros: [Strengths]
    - Cons: [Limitations]
    
    2. [Algorithm 2]
    - Why: [Justification]
    - Pros: [Strengths]
    - Cons: [Limitations]
    
    3. [Algorithm 3]
    - Why: [Justification]
    - Pros: [Strengths]
    - Cons: [Limitations]
    
    === FINAL CHOICE ===
    Best Algorithm: [Algorithm Name]
    - Why Best: [Detailed comparison]
    - Why Others Are Less Suitable: [Explanation]
    """
    
    try:
        response = model.generate_content(prompt)
        return response.text
    except Exception as e:
        return f"Error: {e}\n\nTip: The API key may need enabling at https://aistudio.google.com/"

# Create Gradio interface
with gr.Blocks(title="ML Algorithm Recommender", theme=gr.themes.Soft()) as demo:
    gr.Markdown("""
    # Machine Learning Algorithm Recommender
    Enter your project characteristics to get personalized algorithm recommendations
    """)
    
    with gr.Row():
        with gr.Column():
            problem_type = gr.Textbox(label="Problem Type*", placeholder="classification, regression, clustering...")
            dataset_size = gr.Textbox(label="Dataset Size*", placeholder="small, medium, large or specific number")
            num_features = gr.Textbox(label="Number of Features*", placeholder="few, many, or specific number")
            feature_type = gr.Textbox(label="Feature Types*", placeholder="numerical, categorical, mixed")
            priority = gr.Textbox(label="Priority*", placeholder="accuracy, speed, interpretability")
            additional_info = gr.Textbox(label="Additional Details (optional)", placeholder="Any other important information")
            submit_btn = gr.Button("Get Recommendations", variant="primary")
        
        with gr.Column():
            output = gr.Textbox(label="Recommendation Results", lines=20, interactive=False)
    
    submit_btn.click(
        fn=generate_recommendation,
        inputs=[problem_type, dataset_size, num_features, feature_type, priority, additional_info],
        outputs=output
    )

if __name__ == "__main__":
    demo.launch()