Spaces:
Build error
Build error
prashant commited on
Commit ·
a277c5b
1
Parent(s): acff0ee
Update Space files and use HF secret token
Browse files- .gitignore +8 -0
- app.py +145 -72
- packages.txt +0 -2
- requirements.txt +1 -0
.gitignore
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.env
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.pyc
|
| 4 |
+
.venv/
|
| 5 |
+
venv/
|
| 6 |
+
.ipynb_checkpoints/
|
| 7 |
+
.DS_Store
|
| 8 |
+
*.log
|
app.py
CHANGED
|
@@ -1,112 +1,185 @@
|
|
| 1 |
import os
|
| 2 |
-
import tempfile
|
| 3 |
from typing import Optional
|
| 4 |
|
| 5 |
import gradio as gr
|
| 6 |
-
from
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
from utils.logging_utils import get_logger
|
| 11 |
-
from utils.file_utils import save_uploaded_file
|
| 12 |
|
| 13 |
-
|
|
|
|
| 14 |
|
| 15 |
-
logger = get_logger(__name__)
|
| 16 |
-
agent = ProjectAgent()
|
| 17 |
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
|
| 29 |
-
saved_path = save_uploaded_file(uploaded_file)
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
)
|
| 37 |
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
except Exception as e:
|
| 41 |
-
|
| 42 |
-
|
|
|
|
| 43 |
|
| 44 |
|
| 45 |
-
with gr.Blocks(title=
|
| 46 |
gr.Markdown(
|
| 47 |
-
f"""
|
| 48 |
-
# {settings.APP_NAME}
|
| 49 |
-
A reusable Hugging Face Space template for **any kind of project**.
|
| 50 |
-
|
| 51 |
-
### Supported ideas
|
| 52 |
-
- Data science project explainer
|
| 53 |
-
- Interview answer generator
|
| 54 |
-
- Resume/project summary
|
| 55 |
-
- PDF/image/text analysis
|
| 56 |
-
- Recommendation/prediction demo
|
| 57 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
)
|
| 59 |
|
| 60 |
with gr.Row():
|
| 61 |
with gr.Column():
|
| 62 |
project_type = gr.Dropdown(
|
| 63 |
choices=[
|
| 64 |
-
"
|
| 65 |
-
"
|
| 66 |
"Resume Project Summary",
|
| 67 |
-
"
|
| 68 |
-
"
|
| 69 |
-
"Custom Project"
|
| 70 |
],
|
| 71 |
-
value="
|
| 72 |
-
label="Project Type"
|
| 73 |
-
)
|
| 74 |
-
|
| 75 |
-
user_text = gr.Textbox(
|
| 76 |
-
label="Enter your project/problem statement",
|
| 77 |
-
placeholder="Example: Explain my insurance cross-sell prediction and recommendation project for interview...",
|
| 78 |
-
lines=10,
|
| 79 |
-
max_lines=20
|
| 80 |
-
)
|
| 81 |
-
|
| 82 |
-
uploaded_file = gr.File(
|
| 83 |
-
label="Upload optional file (pdf/txt/image)",
|
| 84 |
-
type="filepath"
|
| 85 |
)
|
| 86 |
|
| 87 |
tone = gr.Radio(
|
| 88 |
-
choices=["
|
| 89 |
value="Interview-ready",
|
| 90 |
-
label="Tone"
|
| 91 |
)
|
| 92 |
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
with gr.Column():
|
| 96 |
-
summary_output = gr.Textbox(
|
| 97 |
-
|
| 98 |
-
lines=12
|
| 99 |
-
)
|
| 100 |
-
report_output = gr.Textbox(
|
| 101 |
-
label="Detailed Report",
|
| 102 |
-
lines=20
|
| 103 |
-
)
|
| 104 |
|
| 105 |
run_btn.click(
|
| 106 |
fn=run_project,
|
| 107 |
-
inputs=[project_type,
|
| 108 |
-
outputs=[summary_output, report_output]
|
| 109 |
)
|
| 110 |
|
| 111 |
-
|
| 112 |
-
demo.launch()
|
|
|
|
| 1 |
import os
|
|
|
|
| 2 |
from typing import Optional
|
| 3 |
|
| 4 |
import gradio as gr
|
| 5 |
+
from huggingface_hub import InferenceClient
|
| 6 |
|
| 7 |
+
APP_TITLE = "ProjectLensAI"
|
| 8 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
# Create client only if token exists
|
| 11 |
+
client = InferenceClient(api_key=HF_TOKEN) if HF_TOKEN else None
|
| 12 |
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
def build_prompt(project_type: str, tone: str, user_text: str) -> str:
|
| 15 |
+
return f"""
|
| 16 |
+
You are an expert data science and machine learning interview assistant.
|
| 17 |
|
| 18 |
+
Task:
|
| 19 |
+
Explain the following project clearly and professionally.
|
| 20 |
+
|
| 21 |
+
Project Type: {project_type}
|
| 22 |
+
Tone: {tone}
|
| 23 |
+
|
| 24 |
+
User Project Description:
|
| 25 |
+
{user_text}
|
| 26 |
+
|
| 27 |
+
Please generate:
|
| 28 |
+
1. Problem Statement
|
| 29 |
+
2. Business Objective
|
| 30 |
+
3. Dataset / Input Description
|
| 31 |
+
4. Preprocessing / Feature Engineering
|
| 32 |
+
5. Model / Approach Used
|
| 33 |
+
6. Evaluation Metrics
|
| 34 |
+
7. Recommendation / Prediction Logic
|
| 35 |
+
8. Business Impact
|
| 36 |
+
9. Interview-Ready Explanation
|
| 37 |
+
10. Short HR-Friendly Summary
|
| 38 |
+
|
| 39 |
+
Keep the answer structured and easy to speak in an interview.
|
| 40 |
+
""".strip()
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def local_fallback(project_type: str, tone: str, user_text: str):
|
| 44 |
+
summary = f"""Project Type: {project_type}
|
| 45 |
+
Tone: {tone}
|
| 46 |
+
|
| 47 |
+
Project Overview:
|
| 48 |
+
{user_text[:300]}"""
|
| 49 |
+
|
| 50 |
+
report = f"""
|
| 51 |
+
PROJECTLENSAI REPORT
|
| 52 |
+
====================
|
| 53 |
+
|
| 54 |
+
1. Problem Statement
|
| 55 |
+
This project focuses on solving a real-world problem using data-driven methods.
|
| 56 |
+
|
| 57 |
+
2. Business Objective
|
| 58 |
+
The goal is to improve decision-making, prediction quality, and business outcomes.
|
| 59 |
+
|
| 60 |
+
3. Dataset / Input Description
|
| 61 |
+
The project uses structured or unstructured input data depending on the use case.
|
| 62 |
+
|
| 63 |
+
4. Preprocessing / Feature Engineering
|
| 64 |
+
Typical preprocessing includes handling missing values, encoding categories,
|
| 65 |
+
scaling numerical features, and selecting relevant variables.
|
| 66 |
+
|
| 67 |
+
5. Model / Approach Used
|
| 68 |
+
The solution may use machine learning, NLP, computer vision, or a custom rule-based pipeline.
|
| 69 |
+
|
| 70 |
+
6. Evaluation Metrics
|
| 71 |
+
Common metrics include accuracy, precision, recall, F1-score, ROC-AUC, RMSE, MAE,
|
| 72 |
+
depending on the task.
|
| 73 |
+
|
| 74 |
+
7. Recommendation / Prediction Logic
|
| 75 |
+
The model predicts likely outcomes and supports recommendations based on learned patterns.
|
| 76 |
+
|
| 77 |
+
8. Business Impact
|
| 78 |
+
The project can help improve efficiency, targeting, automation, and customer experience.
|
| 79 |
+
|
| 80 |
+
9. Interview-Ready Explanation
|
| 81 |
+
In this project, I worked on {project_type.lower()}.
|
| 82 |
+
The goal was to take raw data, preprocess it, build a useful model, evaluate performance,
|
| 83 |
+
and convert the output into actionable business insights.
|
| 84 |
+
|
| 85 |
+
10. HR-Friendly Summary
|
| 86 |
+
This project shows my ability to solve business problems using data, machine learning,
|
| 87 |
+
and clear communication.
|
| 88 |
+
|
| 89 |
+
Original User Input:
|
| 90 |
+
{user_text}
|
| 91 |
+
""".strip()
|
| 92 |
|
| 93 |
+
return summary, report
|
|
|
|
| 94 |
|
| 95 |
+
|
| 96 |
+
def run_project(project_type: str, tone: str, user_text: str):
|
| 97 |
+
if not user_text or not user_text.strip():
|
| 98 |
+
return "Please enter project details.", "Input is empty."
|
| 99 |
+
|
| 100 |
+
# If no HF secret is available, fallback still works
|
| 101 |
+
if client is None:
|
| 102 |
+
return local_fallback(project_type, tone, user_text)
|
| 103 |
+
|
| 104 |
+
prompt = build_prompt(project_type, tone, user_text)
|
| 105 |
+
|
| 106 |
+
try:
|
| 107 |
+
response = client.chat_completion(
|
| 108 |
+
model="meta-llama/Meta-Llama-3.1-8B-Instruct",
|
| 109 |
+
messages=[
|
| 110 |
+
{"role": "system", "content": "You are a helpful AI project explainer."},
|
| 111 |
+
{"role": "user", "content": prompt},
|
| 112 |
+
],
|
| 113 |
+
max_tokens=900,
|
| 114 |
)
|
| 115 |
|
| 116 |
+
content = response.choices[0].message.content.strip()
|
| 117 |
+
|
| 118 |
+
summary = f"""Project Type: {project_type}
|
| 119 |
+
Tone: {tone}
|
| 120 |
+
|
| 121 |
+
Generated successfully using Hugging Face secret token.
|
| 122 |
+
|
| 123 |
+
Preview:
|
| 124 |
+
{content[:500]}"""
|
| 125 |
+
|
| 126 |
+
report = content
|
| 127 |
+
return summary, report
|
| 128 |
|
| 129 |
except Exception as e:
|
| 130 |
+
fallback_summary, fallback_report = local_fallback(project_type, tone, user_text)
|
| 131 |
+
error_note = f"\n\n[HF API fallback used due to error: {str(e)}]"
|
| 132 |
+
return fallback_summary + error_note, fallback_report + error_note
|
| 133 |
|
| 134 |
|
| 135 |
+
with gr.Blocks(title=APP_TITLE) as demo:
|
| 136 |
gr.Markdown(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
"""
|
| 138 |
+
# ProjectLensAI
|
| 139 |
+
Explain any DS/ML/AI project in an interview-ready format.
|
| 140 |
+
|
| 141 |
+
This Space uses your Hugging Face secret token automatically through:
|
| 142 |
+
`HF_TOKEN`
|
| 143 |
+
"""
|
| 144 |
)
|
| 145 |
|
| 146 |
with gr.Row():
|
| 147 |
with gr.Column():
|
| 148 |
project_type = gr.Dropdown(
|
| 149 |
choices=[
|
| 150 |
+
"Insurance Cross-Sell Prediction",
|
| 151 |
+
"Recommendation System",
|
| 152 |
"Resume Project Summary",
|
| 153 |
+
"NLP Project",
|
| 154 |
+
"Computer Vision Project",
|
| 155 |
+
"Custom Project",
|
| 156 |
],
|
| 157 |
+
value="Insurance Cross-Sell Prediction",
|
| 158 |
+
label="Project Type",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
)
|
| 160 |
|
| 161 |
tone = gr.Radio(
|
| 162 |
+
choices=["Interview-ready", "Technical", "Professional", "Simple"],
|
| 163 |
value="Interview-ready",
|
| 164 |
+
label="Tone",
|
| 165 |
)
|
| 166 |
|
| 167 |
+
user_text = gr.Textbox(
|
| 168 |
+
label="Enter your project details",
|
| 169 |
+
lines=12,
|
| 170 |
+
placeholder="Example: I built an insurance cross-sell prediction project where I predicted which health insurance customers are likely to buy vehicle insurance...",
|
| 171 |
+
)
|
| 172 |
+
|
| 173 |
+
run_btn = gr.Button("Generate Explanation", variant="primary")
|
| 174 |
|
| 175 |
with gr.Column():
|
| 176 |
+
summary_output = gr.Textbox(label="Summary", lines=10)
|
| 177 |
+
report_output = gr.Textbox(label="Detailed Explanation", lines=22)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
run_btn.click(
|
| 180 |
fn=run_project,
|
| 181 |
+
inputs=[project_type, tone, user_text],
|
| 182 |
+
outputs=[summary_output, report_output],
|
| 183 |
)
|
| 184 |
|
| 185 |
+
demo.launch()
|
|
|
packages.txt
DELETED
|
@@ -1,2 +0,0 @@
|
|
| 1 |
-
poppler-utils
|
| 2 |
-
tesseract-ocr
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
python-dotenv==1.0.1
|
| 2 |
pydantic==2.9.2
|
| 3 |
pillow==10.4.0
|
|
|
|
| 1 |
+
huggingface_hub
|
| 2 |
python-dotenv==1.0.1
|
| 3 |
pydantic==2.9.2
|
| 4 |
pillow==10.4.0
|