adityya7 commited on
Commit
dea5528
·
verified ·
1 Parent(s): 15ffe75

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -57
app.py CHANGED
@@ -1,64 +1,70 @@
 
 
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
3
 
4
- """
5
- For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
- """
7
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
 
 
 
9
 
10
- def respond(
11
- message,
12
- history: list[tuple[str, str]],
13
- system_message,
14
- max_tokens,
15
- temperature,
16
- top_p,
17
- ):
18
- messages = [{"role": "system", "content": system_message}]
19
-
20
- for val in history:
21
- if val[0]:
22
- messages.append({"role": "user", "content": val[0]})
23
- if val[1]:
24
- messages.append({"role": "assistant", "content": val[1]})
25
-
26
- messages.append({"role": "user", "content": message})
27
-
28
- response = ""
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
- if __name__ == "__main__":
64
- demo.launch()
 
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()