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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import logging
|
| 3 |
+
import requests
|
| 4 |
+
from logging import getLogger, INFO, StreamHandler
|
| 5 |
+
from typing import Dict, List
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
# Setup logging
|
| 9 |
+
logger = logging.getLogger(__name__)
|
| 10 |
+
logger.setLevel(logging.INFO)
|
| 11 |
+
sh = StreamHandler()
|
| 12 |
+
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
| 13 |
+
sh.setFormatter(formatter)
|
| 14 |
+
logger.addHandler(sh)
|
| 15 |
+
|
| 16 |
+
st.set_page_config(page_title="Project Generator", layout="wide")
|
| 17 |
+
|
| 18 |
+
@st.cache_resource
|
| 19 |
+
def load_hf_models():
|
| 20 |
+
"""Load Hugging Face Inference API configuration"""
|
| 21 |
+
api_token = os.environ.get('HF_API_KEY')
|
| 22 |
+
if not api_token:
|
| 23 |
+
raise Exception("HF_API_KEY not found in environment variables")
|
| 24 |
+
|
| 25 |
+
headers = {"Authorization": f"Bearer {api_token}"}
|
| 26 |
+
API_URL = "https://api-inference.huggingface.co/models/google/flan-t5-base"
|
| 27 |
+
|
| 28 |
+
# Test API connection
|
| 29 |
+
try:
|
| 30 |
+
response = requests.post(API_URL, headers=headers, json={"inputs": "test"})
|
| 31 |
+
response.raise_for_status()
|
| 32 |
+
return {"headers": headers, "api_url": API_URL}
|
| 33 |
+
except requests.exceptions.RequestException as e:
|
| 34 |
+
raise Exception(f"Failed to connect to HuggingFace API: {str(e)}")
|
| 35 |
+
|
| 36 |
+
def generate_project_ideas(field: str, tech_stack: str, level: str, hf_config) -> List[Dict]:
|
| 37 |
+
"""Generate project ideas using HuggingFace Inference API"""
|
| 38 |
+
if not hf_config:
|
| 39 |
+
raise Exception("HuggingFace configuration not initialized")
|
| 40 |
+
|
| 41 |
+
# Create prompt for the model
|
| 42 |
+
prompt = f"""Generate a project idea for:
|
| 43 |
+
Field: {field}
|
| 44 |
+
Tech Stack: {tech_stack}
|
| 45 |
+
Level: {level}
|
| 46 |
+
Format: creative and innovative project only"""
|
| 47 |
+
|
| 48 |
+
try:
|
| 49 |
+
response = requests.post(
|
| 50 |
+
hf_config["api_url"],
|
| 51 |
+
headers=hf_config["headers"],
|
| 52 |
+
json={
|
| 53 |
+
"inputs": prompt,
|
| 54 |
+
"parameters": {
|
| 55 |
+
"max_length": 500,
|
| 56 |
+
"temperature": 0.7,
|
| 57 |
+
"num_return_sequences": 3
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
)
|
| 61 |
+
response.raise_for_status()
|
| 62 |
+
|
| 63 |
+
project_ideas = []
|
| 64 |
+
for idea in response.json():
|
| 65 |
+
features = generate_project_features(field.lower(), tech_stack, level)
|
| 66 |
+
tech_stack_list = tech_stack.split(',') if tech_stack else []
|
| 67 |
+
|
| 68 |
+
project = {
|
| 69 |
+
'description': idea.strip(),
|
| 70 |
+
'features': features,
|
| 71 |
+
'tech_stack': tech_stack_list,
|
| 72 |
+
'learning_outcomes': generate_learning_outcomes(tech_stack, level),
|
| 73 |
+
'complexity': estimate_complexity(features, tech_stack_list, level)
|
| 74 |
+
}
|
| 75 |
+
project_ideas.append(project)
|
| 76 |
+
|
| 77 |
+
return project_ideas[:3]
|
| 78 |
+
|
| 79 |
+
except requests.exceptions.RequestException as e:
|
| 80 |
+
logger.error(f"API request failed: {str(e)}")
|
| 81 |
+
raise Exception("Failed to generate project ideas")
|
| 82 |
+
|
| 83 |
+
def generate_project_features(field: str, tech_stack: str, level: str) -> List[str]:
|
| 84 |
+
"""Generate AI-based features for the project"""
|
| 85 |
+
base_features = [
|
| 86 |
+
f"Integration with {tech_stack}",
|
| 87 |
+
"Automated testing suite",
|
| 88 |
+
"CI/CD pipeline",
|
| 89 |
+
"RESTful API architecture",
|
| 90 |
+
"Real-time data processing",
|
| 91 |
+
"Advanced security features",
|
| 92 |
+
"Performance monitoring",
|
| 93 |
+
"Scalable infrastructure"
|
| 94 |
+
]
|
| 95 |
+
|
| 96 |
+
# Adjust number of features based on level
|
| 97 |
+
if level == "Beginner":
|
| 98 |
+
return base_features[:3]
|
| 99 |
+
elif level == "Intermediate":
|
| 100 |
+
return base_features[:5]
|
| 101 |
+
return base_features
|
| 102 |
+
|
| 103 |
+
def estimate_complexity(features: List[str], tech_stack: List[str], level: str) -> str:
|
| 104 |
+
"""Estimate project complexity based on features and tech stack"""
|
| 105 |
+
complexity_score = len(features) + len(tech_stack)
|
| 106 |
+
if level == "Beginner":
|
| 107 |
+
complexity_score *= 0.7
|
| 108 |
+
elif level == "Advanced":
|
| 109 |
+
complexity_score *= 1.3
|
| 110 |
+
|
| 111 |
+
if complexity_score <= 5:
|
| 112 |
+
return "Low"
|
| 113 |
+
elif complexity_score <= 8:
|
| 114 |
+
return "Medium"
|
| 115 |
+
return "High"
|
| 116 |
+
|
| 117 |
+
def generate_learning_outcomes(tech_stack: str, level: str) -> List[str]:
|
| 118 |
+
"""Generate learning outcomes based on technology and level"""
|
| 119 |
+
outcomes = [
|
| 120 |
+
f"Master {tech_stack} fundamentals",
|
| 121 |
+
"Gain practical project experience",
|
| 122 |
+
"Learn industry best practices",
|
| 123 |
+
"Develop problem-solving skills",
|
| 124 |
+
"Build a portfolio-worthy project"
|
| 125 |
+
]
|
| 126 |
+
return outcomes[:3] if level == 'Beginner' else outcomes
|
| 127 |
+
|
| 128 |
+
def main():
|
| 129 |
+
st.title("🚀 Project Generator")
|
| 130 |
+
st.write("Generate personalized project ideas based on your interests and skill level")
|
| 131 |
+
|
| 132 |
+
try:
|
| 133 |
+
hf_config = load_hf_models()
|
| 134 |
+
except Exception as e:
|
| 135 |
+
st.error(f"Failed to initialize HuggingFace API: {str(e)}")
|
| 136 |
+
st.stop()
|
| 137 |
+
|
| 138 |
+
col1, col2 = st.columns(2)
|
| 139 |
+
|
| 140 |
+
with col1:
|
| 141 |
+
field = st.selectbox(
|
| 142 |
+
"Field of Interest",
|
| 143 |
+
["Web Development", "Mobile Development", "Data Science",
|
| 144 |
+
"Machine Learning", "DevOps", "Game Development"]
|
| 145 |
+
)
|
| 146 |
+
|
| 147 |
+
tech_stack = st.multiselect(
|
| 148 |
+
"Technology Stack",
|
| 149 |
+
["Python", "JavaScript", "React", "Node.js", "Flutter",
|
| 150 |
+
"TensorFlow", "PyTorch", "AWS", "Docker", "Unity"],
|
| 151 |
+
max_selections=3
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
+
with col2:
|
| 155 |
+
level = st.selectbox(
|
| 156 |
+
"Experience Level",
|
| 157 |
+
["Beginner", "Intermediate", "Advanced"]
|
| 158 |
+
)
|
| 159 |
+
|
| 160 |
+
project_type = st.selectbox(
|
| 161 |
+
"Project Type",
|
| 162 |
+
["All", "Web Application", "Mobile App", "Data Analysis",
|
| 163 |
+
"Machine Learning", "Automation Tool", "Game"]
|
| 164 |
+
)
|
| 165 |
+
|
| 166 |
+
if st.button("Generate Project Ideas"):
|
| 167 |
+
if not tech_stack:
|
| 168 |
+
st.warning("Please select at least one technology")
|
| 169 |
+
else:
|
| 170 |
+
with st.spinner("Generating project ideas..."):
|
| 171 |
+
try:
|
| 172 |
+
project_ideas = generate_project_ideas(
|
| 173 |
+
field,
|
| 174 |
+
",".join(tech_stack),
|
| 175 |
+
level,
|
| 176 |
+
hf_config
|
| 177 |
+
)
|
| 178 |
+
|
| 179 |
+
if project_ideas:
|
| 180 |
+
for idx, idea in enumerate(project_ideas, 1):
|
| 181 |
+
with st.expander(f"Project Idea {idx}: {idea['description']}", expanded=True):
|
| 182 |
+
st.write("**Features:**")
|
| 183 |
+
for feature in idea['features']:
|
| 184 |
+
st.write(f"- {feature}")
|
| 185 |
+
|
| 186 |
+
st.write("\n**Tech Stack:**")
|
| 187 |
+
st.write(", ".join(idea['tech_stack']))
|
| 188 |
+
|
| 189 |
+
complexity = estimate_complexity(idea['features'], idea['tech_stack'], level)
|
| 190 |
+
st.write(f"\n**Estimated Complexity:** {complexity}")
|
| 191 |
+
|
| 192 |
+
st.write("\n**Learning Outcomes:**")
|
| 193 |
+
for outcome in idea['learning_outcomes']:
|
| 194 |
+
st.write(f"- {outcome}")
|
| 195 |
+
|
| 196 |
+
if 'resources' in idea:
|
| 197 |
+
st.write("\n**Useful Resources:**")
|
| 198 |
+
for resource in idea['resources']:
|
| 199 |
+
st.write(f"- [{resource}]({resource})")
|
| 200 |
+
else:
|
| 201 |
+
st.error("Failed to generate project ideas. Please try again.")
|
| 202 |
+
except Exception as e:
|
| 203 |
+
st.error(f"Error: {str(e)}")
|
| 204 |
+
|
| 205 |
+
if __name__ == "__main__":
|
| 206 |
+
main()
|