Surbhi commited on
Commit
a73d60f
Β·
1 Parent(s): d79d9bd

Initial commit

Browse files
Files changed (4) hide show
  1. README.md +14 -12
  2. app.py +88 -0
  3. dataset.csv +14 -0
  4. requirements.txt +4 -0
README.md CHANGED
@@ -1,13 +1,15 @@
1
- ---
2
- title: Ml Code Generator
3
- emoji: πŸ“Š
4
- colorFrom: indigo
5
- colorTo: purple
6
- sdk: streamlit
7
- sdk_version: 1.43.2
8
- app_file: app.py
9
- pinned: false
10
- short_description: SteamLit app allowing users to generate ML model code
11
- ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AI Code Generator (Streamlit)
 
 
 
 
 
 
 
 
 
 
2
 
3
+ Generate AI model training code in Python with **one click**!
4
+ Simply choose a **model, task, and problem**, and the **code will be generated** for you.
5
+
6
+ ## Features
7
+ βœ… Supports KNN, SVM, Random Forest, Decision Tree, and Perceptron
8
+ βœ… Choose between **classification** and **regression**
9
+ βœ… Select problems like **Spam Detection, House Price Prediction, Fraud Detection**, etc.
10
+ βœ… One-click **download** `.py` and `.ipynb` files
11
+
12
+ ## Installation & Run
13
+ ```bash
14
+ pip install -r requirements.txt
15
+ streamlit run app.py
app.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import textwrap
4
+
5
+ # Sidebar UI
6
+ st.sidebar.title("AI Code Generator 🧠")
7
+ st.sidebar.markdown("Generate AI models instantly!")
8
+
9
+ # Model Selection
10
+ model_options = ["KNN", "SVM", "Random Forest", "Decision Tree", "Perceptron"]
11
+ model = st.sidebar.selectbox("Choose a Model:", model_options)
12
+
13
+ # Task Selection
14
+ task_options = ["Classification", "Regression"]
15
+ task = st.sidebar.selectbox("Choose a Task:", task_options)
16
+
17
+ # Problem Selection based on Task and Model
18
+ problems = {
19
+ "Classification": {
20
+ "KNN": ["Disease Prediction", "Spam Detection"],
21
+ "SVM": ["Image Recognition", "Text Classification"],
22
+ "Random Forest": ["Fraud Detection", "Customer Segmentation"],
23
+ "Decision Tree": ["Loan Approval", "Churn Prediction"],
24
+ "Perceptron": ["Handwritten Digit Recognition", "Sentiment Analysis"]
25
+ },
26
+ "Regression": {
27
+ "KNN": ["House Price Prediction", "Stock Prediction"],
28
+ "SVM": ["Sales Forecasting", "Stock Market Trends"],
29
+ "Random Forest": ["Energy Consumption", "Patient Survival Prediction"],
30
+ "Decision Tree": ["House Price Estimation", "Revenue Prediction"],
31
+ "Perceptron": ["Weather Forecasting", "Traffic Flow Prediction"]
32
+ }
33
+ }
34
+
35
+ problem = st.sidebar.selectbox("Choose a Problem:", problems[task][model])
36
+
37
+ # Generate AI Model Code
38
+ def generate_code(model, task, problem):
39
+ model_mapping = {
40
+ "KNN": "KNeighborsClassifier" if task == "Classification" else "KNeighborsRegressor",
41
+ "SVM": "SVC" if task == "Classification" else "SVR",
42
+ "Random Forest": "RandomForestClassifier" if task == "Classification" else "RandomForestRegressor",
43
+ "Decision Tree": "DecisionTreeClassifier" if task == "Classification" else "DecisionTreeRegressor",
44
+ "Perceptron": "Perceptron" if task == "Classification" else "Perceptron"
45
+ }
46
+
47
+ selected_model = model_mapping[model]
48
+
49
+ template = f"""
50
+ import numpy as np
51
+ import pandas as pd
52
+ from sklearn.model_selection import train_test_split
53
+ from sklearn.preprocessing import StandardScaler
54
+ from sklearn.{model.lower()} import {selected_model}
55
+
56
+ # Load Dataset (Replace with your own dataset)
57
+ data = pd.read_csv('dataset.csv')
58
+ X = data.iloc[:, :-1] # Features
59
+ y = data.iloc[:, -1] # Target
60
+
61
+ # Train-Test Split
62
+ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
63
+
64
+ # Standardize Features (if needed)
65
+ scaler = StandardScaler()
66
+ X_train = scaler.fit_transform(X_train)
67
+ X_test = scaler.transform(X_test)
68
+
69
+ # Model Initialization
70
+ model = {selected_model}()
71
+
72
+ # Training the model
73
+ model.fit(X_train, y_train)
74
+
75
+ # Evaluate Model
76
+ accuracy = model.score(X_test, y_test)
77
+ print("Model Accuracy:", accuracy)
78
+ """
79
+ return textwrap.dedent(template)
80
+
81
+ code = generate_code(model, task, problem)
82
+ st.code(code, language="python")
83
+
84
+ # Download Buttons
85
+ st.download_button("🐍 Download (.py)", code, "ai_model.py")
86
+ st.download_button("πŸ““ Download (.ipynb)", code, "ai_model.ipynb")
87
+
88
+ st.success("Code generated! Download and do magic! ✨")
dataset.csv ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Fake dataset for AI Code Generator
2
+ # You can replace this with your own dataset
3
+
4
+ feature1,feature2,feature3,feature4,target
5
+ 34,180,1,50000,0
6
+ 25,165,0,60000,1
7
+ 40,175,1,55000,0
8
+ 30,170,0,62000,1
9
+ 45,185,1,58000,0
10
+ 28,160,0,57000,1
11
+ 35,178,1,53000,0
12
+ 50,190,1,49000,1
13
+ 23,158,0,61000,0
14
+ 38,172,1,56000,1
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit
2
+ scikit-learn
3
+ pandas
4
+ numpy