Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,64 +1,70 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
-
from huggingface_hub import InferenceClient
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
|
|
|
|
|
9 |
|
10 |
-
def
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
for message in client.chat_completion(
|
31 |
-
messages,
|
32 |
-
max_tokens=max_tokens,
|
33 |
-
stream=True,
|
34 |
-
temperature=temperature,
|
35 |
-
top_p=top_p,
|
36 |
-
):
|
37 |
-
token = message.choices[0].delta.content
|
38 |
-
|
39 |
-
response += token
|
40 |
-
yield response
|
41 |
-
|
42 |
-
|
43 |
-
"""
|
44 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
45 |
-
"""
|
46 |
-
demo = gr.ChatInterface(
|
47 |
-
respond,
|
48 |
-
additional_inputs=[
|
49 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
50 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
51 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
52 |
-
gr.Slider(
|
53 |
-
minimum=0.1,
|
54 |
-
maximum=1.0,
|
55 |
-
value=0.95,
|
56 |
-
step=0.05,
|
57 |
-
label="Top-p (nucleus sampling)",
|
58 |
-
),
|
59 |
-
],
|
60 |
)
|
61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
-
|
64 |
-
|
|
|
1 |
+
import os
|
2 |
+
import google.generativeai as genai
|
3 |
import gradio as gr
|
|
|
4 |
|
5 |
+
# Set up Google API key from environment variable
|
6 |
+
API_KEY = os.getenv("GOOGLE_API_KEY")
|
7 |
+
if not API_KEY:
|
8 |
+
raise ValueError("GOOGLE_API_KEY not set. Add it in Hugging Face Space Secrets.")
|
9 |
|
10 |
+
# Configure the Google Generative AI client
|
11 |
+
genai.configure(api_key=API_KEY)
|
12 |
|
13 |
+
def generate_career_plan(education, skills, internships, interests):
|
14 |
+
"""Generate a dynamic career plan using Google Gemini API without career goals."""
|
15 |
+
# Construct the prompt without career goals
|
16 |
+
prompt = (
|
17 |
+
f"You are a highly knowledgeable career advisor. Create a detailed, actionable career plan "
|
18 |
+
f"tailored to the following user inputs:\n"
|
19 |
+
f"- Engineering Education: {education}\n"
|
20 |
+
f"- Skills: {skills}\n"
|
21 |
+
f"- Internships/Experience: {internships}\n"
|
22 |
+
f"- Interests: {interests}\n\n"
|
23 |
+
f"Structure the plan as follows:\n"
|
24 |
+
f"1. Short-term steps : Break this section down into:\n"
|
25 |
+
f" a. Immediate actions (0–3 months): Quick wins or high-impact tasks based on their current skills.\n"
|
26 |
+
f" b. Mid-term steps (5–8 months): Actions to deepen expertise, expand network, or build relevant experience.\n"
|
27 |
+
f" c. Longer short-term (1–2 years): Projects, certifications, or job transitions to solidify the foundation.\n"
|
28 |
+
f"2. Long-term steps (3–5 years): Steps to advance their career based on interests and background.\n"
|
29 |
+
f"3. Job roles to target: Relevant positions based on their profile.\n"
|
30 |
+
f"4. Skills to learn: New skills to acquire for success.\n"
|
31 |
+
f"5. Resources: Recommended courses, books, or tools (be specific).\n"
|
32 |
+
f"Ensure the plan is concise, practical, and directly reflects the user's inputs."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
)
|
34 |
|
35 |
+
try:
|
36 |
+
# Initialize the Gemini model
|
37 |
+
model = genai.GenerativeModel("gemini-1.5-flash") # Adjust model name if needed
|
38 |
+
response = model.generate_content(prompt)
|
39 |
+
|
40 |
+
# Check if response is valid
|
41 |
+
if not response.text:
|
42 |
+
return "Error: No response generated. Check API key or model availability."
|
43 |
+
return response.text
|
44 |
+
except Exception as e:
|
45 |
+
return f"Error: {str(e)}. Check your API key or network connection."
|
46 |
+
|
47 |
+
# Gradio interface without Career Goals
|
48 |
+
with gr.Blocks(title="Career Guidance Chatbot") as demo:
|
49 |
+
gr.Markdown("# Career Guidance Chatbot")
|
50 |
+
gr.Markdown("Enter your details to get a personalized career plan powered by Google Gemini.Response :WAIT For 10 Sec..")
|
51 |
+
|
52 |
+
with gr.Row():
|
53 |
+
with gr.Column():
|
54 |
+
education = gr.Textbox(label="Engineering Education (e.g., Computer Science, Mechanical)")
|
55 |
+
skills = gr.Textbox(label="Skills (e.g., Python, CAD, project management)")
|
56 |
+
internships = gr.Textbox(label="Internships/Experience (e.g., 3 months at XYZ Corp)")
|
57 |
+
interests = gr.Textbox(label="Interests (e.g., AI, robotics, sustainable energy)")
|
58 |
+
submit_btn = gr.Button("Generate Career Plan")
|
59 |
+
|
60 |
+
with gr.Column():
|
61 |
+
output = gr.Markdown(label="Your Career Plan")
|
62 |
+
|
63 |
+
submit_btn.click(
|
64 |
+
fn=generate_career_plan,
|
65 |
+
inputs=[education, skills, internships, interests],
|
66 |
+
outputs=output
|
67 |
+
)
|
68 |
|
69 |
+
# Launch the app
|
70 |
+
demo.launch()
|