Spaces:
Sleeping
Sleeping
changed chat interface to now use blocks for better UI
Browse files
app.py
CHANGED
|
@@ -12,7 +12,6 @@ from sentence_transformers import SentenceTransformer
|
|
| 12 |
with open("knowledge_base.txt", "r", encoding="utf-8") as f:
|
| 13 |
knowledge_base = f.read()
|
| 14 |
|
| 15 |
-
# Split into chunks
|
| 16 |
chunks = [chunk.strip() for chunk in knowledge_base.split("\n\n") if chunk.strip()]
|
| 17 |
|
| 18 |
# ---------------------------
|
|
@@ -20,8 +19,6 @@ chunks = [chunk.strip() for chunk in knowledge_base.split("\n\n") if chunk.strip
|
|
| 20 |
# ---------------------------
|
| 21 |
|
| 22 |
embedding_model = SentenceTransformer("all-MiniLM-L6-v2")
|
| 23 |
-
|
| 24 |
-
# Precompute embeddings
|
| 25 |
chunk_embeddings = embedding_model.encode(chunks)
|
| 26 |
|
| 27 |
# ---------------------------
|
|
@@ -77,15 +74,12 @@ Guidelines:
|
|
| 77 |
Context:
|
| 78 |
{context}
|
| 79 |
"""
|
| 80 |
-
}
|
| 81 |
-
]
|
| 82 |
-
|
| 83 |
-
messages.append(
|
| 84 |
{
|
| 85 |
"role": "user",
|
| 86 |
"content": message
|
| 87 |
}
|
| 88 |
-
|
| 89 |
|
| 90 |
response = client.chat_completion(
|
| 91 |
messages=messages,
|
|
@@ -94,42 +88,67 @@ Context:
|
|
| 94 |
|
| 95 |
return response.choices[0].message.content.strip()
|
| 96 |
|
| 97 |
-
|
| 98 |
# ---------------------------
|
| 99 |
-
#
|
| 100 |
# ---------------------------
|
| 101 |
|
| 102 |
-
|
| 103 |
-
π Welcome to Pathway AI!
|
| 104 |
-
|
| 105 |
-
I'm here to help students discover opportunities, learning resources, mentorship programs, scholarships, and career pathways.
|
| 106 |
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
-
|
|
|
|
|
|
|
| 110 |
"""
|
| 111 |
|
| 112 |
-
|
| 113 |
# ---------------------------
|
| 114 |
-
#
|
| 115 |
# ---------------------------
|
| 116 |
|
| 117 |
-
|
| 118 |
-
fn=respond,
|
| 119 |
|
| 120 |
-
|
|
|
|
| 121 |
|
| 122 |
-
|
| 123 |
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
-
chatbox.launch()
|
|
|
|
| 12 |
with open("knowledge_base.txt", "r", encoding="utf-8") as f:
|
| 13 |
knowledge_base = f.read()
|
| 14 |
|
|
|
|
| 15 |
chunks = [chunk.strip() for chunk in knowledge_base.split("\n\n") if chunk.strip()]
|
| 16 |
|
| 17 |
# ---------------------------
|
|
|
|
| 19 |
# ---------------------------
|
| 20 |
|
| 21 |
embedding_model = SentenceTransformer("all-MiniLM-L6-v2")
|
|
|
|
|
|
|
| 22 |
chunk_embeddings = embedding_model.encode(chunks)
|
| 23 |
|
| 24 |
# ---------------------------
|
|
|
|
| 74 |
Context:
|
| 75 |
{context}
|
| 76 |
"""
|
| 77 |
+
},
|
|
|
|
|
|
|
|
|
|
| 78 |
{
|
| 79 |
"role": "user",
|
| 80 |
"content": message
|
| 81 |
}
|
| 82 |
+
]
|
| 83 |
|
| 84 |
response = client.chat_completion(
|
| 85 |
messages=messages,
|
|
|
|
| 88 |
|
| 89 |
return response.choices[0].message.content.strip()
|
| 90 |
|
|
|
|
| 91 |
# ---------------------------
|
| 92 |
+
# UI Theme
|
| 93 |
# ---------------------------
|
| 94 |
|
| 95 |
+
theme = gr.themes.Soft()
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
+
css = """
|
| 98 |
+
footer {
|
| 99 |
+
display: none;
|
| 100 |
+
}
|
| 101 |
|
| 102 |
+
.gradio-container {
|
| 103 |
+
max-width: 1000px !important;
|
| 104 |
+
}
|
| 105 |
"""
|
| 106 |
|
|
|
|
| 107 |
# ---------------------------
|
| 108 |
+
# Build UI
|
| 109 |
# ---------------------------
|
| 110 |
|
| 111 |
+
with gr.Blocks(theme=theme, css=css) as demo:
|
|
|
|
| 112 |
|
| 113 |
+
gr.Markdown("""
|
| 114 |
+
# π Pathway AI
|
| 115 |
|
| 116 |
+
### Your guide to opportunities and growth
|
| 117 |
|
| 118 |
+
Helping students discover:
|
| 119 |
+
|
| 120 |
+
π Scholarships
|
| 121 |
+
π Opportunities
|
| 122 |
+
π Women in STEM
|
| 123 |
+
π€ Mentorship
|
| 124 |
+
π» Learning Resources
|
| 125 |
+
π§ Career Exploration
|
| 126 |
+
""")
|
| 127 |
+
|
| 128 |
+
gr.Markdown("""
|
| 129 |
+
### π‘ Try asking:
|
| 130 |
+
|
| 131 |
+
β’ What scholarships are available for women in STEM?
|
| 132 |
+
|
| 133 |
+
β’ How can I find a mentor in technology?
|
| 134 |
+
|
| 135 |
+
β’ What opportunities are available for high school students interested in AI?
|
| 136 |
+
|
| 137 |
+
β’ I want to become a software engineer. Where should I start?
|
| 138 |
+
""")
|
| 139 |
+
|
| 140 |
+
chatbot = gr.ChatInterface(
|
| 141 |
+
fn=respond,
|
| 142 |
+
examples=[
|
| 143 |
+
"What scholarships are available for women in STEM?",
|
| 144 |
+
"How can I find a mentor in technology?",
|
| 145 |
+
"What opportunities are available for high school students interested in AI?",
|
| 146 |
+
"I want to become a software engineer. Where should I start?",
|
| 147 |
+
"What coding resources are best for beginners?",
|
| 148 |
+
"Tell me about women leaders in STEM.",
|
| 149 |
+
"I want to learn machine learning. What resources would you recommend?"
|
| 150 |
+
]
|
| 151 |
+
)
|
| 152 |
+
|
| 153 |
+
demo.launch()
|
| 154 |
|
|
|