Piyusha55 commited on
Commit
2d9bf03
Β·
verified Β·
1 Parent(s): ec7bf46

changed chat interface to now use blocks for better UI

Browse files
Files changed (1) hide show
  1. app.py +52 -33
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
- # Welcome Message
100
  # ---------------------------
101
 
102
- WELCOME_MESSAGE = """
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
- Whether you're exploring STEM, looking for scholarships, searching for coding resources, or figuring out your next steps, I'm here to help.
 
 
 
108
 
109
- Try one of the example questions below!
 
 
110
  """
111
 
112
-
113
  # ---------------------------
114
- # Gradio Interface
115
  # ---------------------------
116
 
117
- chatbox = gr.ChatInterface(
118
- fn=respond,
119
 
120
- title="🌟 Pathway AI",
 
121
 
122
- description=WELCOME_MESSAGE,
123
 
124
- examples=[
125
- "What scholarships are available for women in STEM?",
126
- "How can I find a mentor in technology?",
127
- "What opportunities are available for high school students interested in AI?",
128
- "I want to become a software engineer. Where should I start?",
129
- "What coding resources are best for beginners?",
130
- "Tell me about women leaders in STEM.",
131
- "I want to learn machine learning. What resources would you recommend?"
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