File size: 5,518 Bytes
ecb69bb
 
 
 
a277c5b
ecb69bb
a277c5b
 
ecb69bb
a277c5b
 
ecb69bb
 
a277c5b
 
 
ecb69bb
a277c5b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ecb69bb
a277c5b
ecb69bb
a277c5b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ecb69bb
 
a277c5b
 
 
 
 
 
 
 
 
 
 
 
ecb69bb
 
a277c5b
 
 
ecb69bb
 
a277c5b
ecb69bb
 
a277c5b
 
 
 
 
 
ecb69bb
 
 
 
 
 
a277c5b
 
ecb69bb
a277c5b
 
 
ecb69bb
a277c5b
 
ecb69bb
 
 
a277c5b
ecb69bb
a277c5b
ecb69bb
 
a277c5b
 
 
 
 
 
 
ecb69bb
 
a277c5b
 
ecb69bb
 
 
a277c5b
 
ecb69bb
 
a277c5b
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
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()