Spaces:
Build error
Build error
Download app.py from prashantpatil3299/ProjectLensAI: direct link, hf CLI and curl.
- Browser
- Download file 5.52 kB
-
https://huggingface.co/spaces/prashantpatil3299/ProjectLensAI/resolve/main/app.py
- Command line
-
hf download hf://spaces/prashantpatil3299/ProjectLensAI/app.py
-
curl -L -o app.py https://huggingface.co/spaces/prashantpatil3299/ProjectLensAI/resolve/main/app.py
5.52 kB
| import os | |
| from typing import Optional | |
| import gradio as gr | |
| from huggingface_hub import InferenceClient | |
| APP_TITLE = "ProjectLensAI" | |
| HF_TOKEN = os.getenv("HF_TOKEN") | |
| # Create client only if token exists | |
| client = InferenceClient(api_key=HF_TOKEN) if HF_TOKEN else None | |
| def build_prompt(project_type: str, tone: str, user_text: str) -> str: | |
| return f""" | |
| You are an expert data science and machine learning interview assistant. | |
| Task: | |
| Explain the following project clearly and professionally. | |
| Project Type: {project_type} | |
| Tone: {tone} | |
| User Project Description: | |
| {user_text} | |
| Please generate: | |
| 1. Problem Statement | |
| 2. Business Objective | |
| 3. Dataset / Input Description | |
| 4. Preprocessing / Feature Engineering | |
| 5. Model / Approach Used | |
| 6. Evaluation Metrics | |
| 7. Recommendation / Prediction Logic | |
| 8. Business Impact | |
| 9. Interview-Ready Explanation | |
| 10. Short HR-Friendly Summary | |
| Keep the answer structured and easy to speak in an interview. | |
| """.strip() | |
| def local_fallback(project_type: str, tone: str, user_text: str): | |
| summary = f"""Project Type: {project_type} | |
| Tone: {tone} | |
| Project Overview: | |
| {user_text[:300]}""" | |
| report = f""" | |
| PROJECTLENSAI REPORT | |
| ==================== | |
| 1. Problem Statement | |
| This project focuses on solving a real-world problem using data-driven methods. | |
| 2. Business Objective | |
| The goal is to improve decision-making, prediction quality, and business outcomes. | |
| 3. Dataset / Input Description | |
| The project uses structured or unstructured input data depending on the use case. | |
| 4. Preprocessing / Feature Engineering | |
| Typical preprocessing includes handling missing values, encoding categories, | |
| scaling numerical features, and selecting relevant variables. | |
| 5. Model / Approach Used | |
| The solution may use machine learning, NLP, computer vision, or a custom rule-based pipeline. | |
| 6. Evaluation Metrics | |
| Common metrics include accuracy, precision, recall, F1-score, ROC-AUC, RMSE, MAE, | |
| depending on the task. | |
| 7. Recommendation / Prediction Logic | |
| The model predicts likely outcomes and supports recommendations based on learned patterns. | |
| 8. Business Impact | |
| The project can help improve efficiency, targeting, automation, and customer experience. | |
| 9. Interview-Ready Explanation | |
| In this project, I worked on {project_type.lower()}. | |
| The goal was to take raw data, preprocess it, build a useful model, evaluate performance, | |
| and convert the output into actionable business insights. | |
| 10. HR-Friendly Summary | |
| This project shows my ability to solve business problems using data, machine learning, | |
| and clear communication. | |
| Original User Input: | |
| {user_text} | |
| """.strip() | |
| return summary, report | |
| def run_project(project_type: str, tone: str, user_text: str): | |
| if not user_text or not user_text.strip(): | |
| return "Please enter project details.", "Input is empty." | |
| # If no HF secret is available, fallback still works | |
| if client is None: | |
| return local_fallback(project_type, tone, user_text) | |
| prompt = build_prompt(project_type, tone, user_text) | |
| try: | |
| response = client.chat_completion( | |
| model="meta-llama/Meta-Llama-3.1-8B-Instruct", | |
| messages=[ | |
| {"role": "system", "content": "You are a helpful AI project explainer."}, | |
| {"role": "user", "content": prompt}, | |
| ], | |
| max_tokens=900, | |
| ) | |
| content = response.choices[0].message.content.strip() | |
| summary = f"""Project Type: {project_type} | |
| Tone: {tone} | |
| Generated successfully using Hugging Face secret token. | |
| Preview: | |
| {content[:500]}""" | |
| report = content | |
| return summary, report | |
| except Exception as e: | |
| fallback_summary, fallback_report = local_fallback(project_type, tone, user_text) | |
| error_note = f"\n\n[HF API fallback used due to error: {str(e)}]" | |
| return fallback_summary + error_note, fallback_report + error_note | |
| with gr.Blocks(title=APP_TITLE) as demo: | |
| gr.Markdown( | |
| """ | |
| # ProjectLensAI | |
| Explain any DS/ML/AI project in an interview-ready format. | |
| This Space uses your Hugging Face secret token automatically through: | |
| `HF_TOKEN` | |
| """ | |
| ) | |
| with gr.Row(): | |
| with gr.Column(): | |
| project_type = gr.Dropdown( | |
| choices=[ | |
| "Insurance Cross-Sell Prediction", | |
| "Recommendation System", | |
| "Resume Project Summary", | |
| "NLP Project", | |
| "Computer Vision Project", | |
| "Custom Project", | |
| ], | |
| value="Insurance Cross-Sell Prediction", | |
| label="Project Type", | |
| ) | |
| tone = gr.Radio( | |
| choices=["Interview-ready", "Technical", "Professional", "Simple"], | |
| value="Interview-ready", | |
| label="Tone", | |
| ) | |
| user_text = gr.Textbox( | |
| label="Enter your project details", | |
| lines=12, | |
| placeholder="Example: I built an insurance cross-sell prediction project where I predicted which health insurance customers are likely to buy vehicle insurance...", | |
| ) | |
| run_btn = gr.Button("Generate Explanation", variant="primary") | |
| with gr.Column(): | |
| summary_output = gr.Textbox(label="Summary", lines=10) | |
| report_output = gr.Textbox(label="Detailed Explanation", lines=22) | |
| run_btn.click( | |
| fn=run_project, | |
| inputs=[project_type, tone, user_text], | |
| outputs=[summary_output, report_output], | |
| ) | |
| demo.launch() |