Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,125 +1,90 @@
|
|
| 1 |
-
import os
|
| 2 |
from datetime import datetime
|
| 3 |
from groq import Groq
|
| 4 |
from docx import Document
|
| 5 |
from docx.shared import Pt
|
| 6 |
-
import gradio as gr
|
| 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 |
-
Welcome to the AI Textbook Generator developed by **Najaf Ali Sharqi**.
|
| 92 |
-
|
| 93 |
-
### π Instructions:
|
| 94 |
-
1. Enter the **textbook topic** and **grade level**
|
| 95 |
-
2. Click **Generate Table of Contents**
|
| 96 |
-
3. Tap a chapter button to generate its content
|
| 97 |
-
4. After generating all chapters, click **Download Word File**
|
| 98 |
""")
|
| 99 |
-
|
| 100 |
-
with gr.Row():
|
| 101 |
-
topic_input = gr.Textbox(label="Textbook Topic", placeholder="e.g., Basics of AI")
|
| 102 |
-
grade_input = gr.Textbox(label="Grade Level", placeholder="e.g., 6")
|
| 103 |
-
|
| 104 |
-
toc_btn = gr.Button("πΉ Generate Table of Contents")
|
| 105 |
-
toc_output = gr.Textbox(label="π Table of Contents", lines=10)
|
| 106 |
-
|
| 107 |
-
toc_btn.click(fn=generate_toc, inputs=topic_input, outputs=toc_output)
|
| 108 |
-
|
| 109 |
-
gr.Markdown("### π₯ Generate Chapter Content")
|
| 110 |
-
|
| 111 |
-
with gr.Row():
|
| 112 |
-
for i in range(1, 8):
|
| 113 |
-
btn = gr.Button(f"Chapter {i}")
|
| 114 |
-
btn.click(fn=generate_chapter, inputs=[topic_input, gr.Textbox(value=str(i), visible=False)], outputs=gr.Textbox(label="π Chapter Content", lines=30))
|
| 115 |
-
|
| 116 |
-
gr.Markdown("### π€ Export Full Textbook")
|
| 117 |
-
download_btn = gr.Button("β¬οΈ Download Word File")
|
| 118 |
-
download_file = gr.File()
|
| 119 |
-
|
| 120 |
-
download_btn.click(fn=download_textbook, inputs=[topic_input, grade_input], outputs=download_file)
|
| 121 |
-
|
| 122 |
-
gr.Markdown("---")
|
| 123 |
-
gr.Markdown("App developed by **Najaf Ali Sharqi** | Powered by **Groq + Gradio**")
|
| 124 |
-
|
| 125 |
-
demo.launch()
|
|
|
|
| 1 |
+
import os
|
| 2 |
from datetime import datetime
|
| 3 |
from groq import Groq
|
| 4 |
from docx import Document
|
| 5 |
from docx.shared import Pt
|
|
|
|
| 6 |
|
| 7 |
+
import streamlit as st
|
| 8 |
+
|
| 9 |
+
# ==== PAGE CONFIG ====
|
| 10 |
+
st.set_page_config(page_title="Smart Career Advisor", layout="centered")
|
| 11 |
+
|
| 12 |
+
# ==== GROQ CLIENT SETUP ====
|
| 13 |
+
client = Groq(api_key=os.getenv("GROQ_API_KEY"))
|
| 14 |
+
MODEL = "llama3-70b-8192"
|
| 15 |
+
|
| 16 |
+
def query_groq(prompt):
|
| 17 |
+
try:
|
| 18 |
+
response = client.chat.completions.create(
|
| 19 |
+
model=MODEL,
|
| 20 |
+
messages=[{"role": "user", "content": prompt}]
|
| 21 |
+
)
|
| 22 |
+
return response.choices[0].message.content
|
| 23 |
+
except Exception as e:
|
| 24 |
+
return f"Error: {str(e)}"
|
| 25 |
+
|
| 26 |
+
# ==== SIDEBAR FORM ====
|
| 27 |
+
with st.sidebar:
|
| 28 |
+
st.title("π§ User Input")
|
| 29 |
+
user_name = st.text_input("π€ Your Full Name")
|
| 30 |
+
education = st.selectbox("π Education Level", ["Matric", "Intermediate", "Bachelor", "Master", "PhD"])
|
| 31 |
+
major = st.text_input("π Field of Study / Major")
|
| 32 |
+
interests = st.multiselect("π― Interests", ["Technology", "Arts", "Business", "Healthcare", "Teaching", "Design", "Public Service", "Engineering", "Law", "Science"])
|
| 33 |
+
work_style = st.radio("π’ Preferred Work Style", ["Remote", "Field-based", "Office", "Freelance"])
|
| 34 |
+
goal = st.selectbox("π Career Goal", ["High Income", "Flexibility", "Social Impact", "Research", "Innovation"])
|
| 35 |
+
skills = st.text_area("π οΈ Your Skills or Strengths", placeholder="e.g., communication, coding, writing")
|
| 36 |
+
industry = st.text_input("π Preferred Industry (optional)")
|
| 37 |
+
submit = st.button("π Generate Career Report")
|
| 38 |
+
|
| 39 |
+
# ==== MAIN TITLE ====
|
| 40 |
+
st.title("π Smart Career Advisor")
|
| 41 |
+
st.markdown("AI-powered suggestions based on your background and preferences.")
|
| 42 |
+
|
| 43 |
+
# ==== MAIN LOGIC ====
|
| 44 |
+
if submit and user_name and interests:
|
| 45 |
+
user_profile = f"""
|
| 46 |
+
Name: {user_name}
|
| 47 |
+
Education: {education}
|
| 48 |
+
Field of Study: {major}
|
| 49 |
+
Interests: {', '.join(interests)}
|
| 50 |
+
Preferred Work Style: {work_style}
|
| 51 |
+
Career Goal: {goal}
|
| 52 |
+
Skills: {skills}
|
| 53 |
+
Preferred Industry: {industry}
|
| 54 |
+
"""
|
| 55 |
+
|
| 56 |
+
groq_prompt = f"""
|
| 57 |
+
You are a professional career counselor. Based on the following user profile, provide a comprehensive advisory report in 5 clear sections:
|
| 58 |
+
1. Suitable Career Paths
|
| 59 |
+
2. Job Roles/Occupations
|
| 60 |
+
3. Required Skills or Certifications
|
| 61 |
+
4. Recommended Learning Resources
|
| 62 |
+
5. Tips to Get Started
|
| 63 |
+
|
| 64 |
+
Please be specific, practical, and professional.
|
| 65 |
+
|
| 66 |
+
USER PROFILE:
|
| 67 |
+
{user_profile}
|
| 68 |
+
"""
|
| 69 |
+
|
| 70 |
+
with st.spinner("π Analyzing your profile..."):
|
| 71 |
+
groq_response = query_groq(groq_prompt)
|
| 72 |
+
|
| 73 |
+
# ==== DISPLAY RESULT ====
|
| 74 |
+
st.success("β
Career Report Generated")
|
| 75 |
+
st.markdown(f"**Name:** {user_name}")
|
| 76 |
+
|
| 77 |
+
sections = groq_response.split('\n\n')
|
| 78 |
+
for sec in sections:
|
| 79 |
+
if sec.strip():
|
| 80 |
+
with st.expander(sec.strip().split('\n')[0]):
|
| 81 |
+
st.markdown(sec.strip())
|
| 82 |
+
|
| 83 |
+
# ==== FOOTER ====
|
| 84 |
+
st.markdown("---")
|
| 85 |
+
st.markdown("**π¨βπ» Developed by Najaf Ali Sharqi**")
|
| 86 |
+
st.markdown("""
|
| 87 |
+
**About the Developer:**
|
| 88 |
+
Najaf Ali Sharqi is an educationist and AI trainer with a strong background in Educational Technology and Curriculum Development.
|
| 89 |
+
He specializes in developing user-friendly GenAI tools for educators and students in low-resource environments, and is passionate about integrating technology with social impact.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|