Spaces:
Sleeping
Sleeping
added checkboxes
Browse files
app.py
CHANGED
|
@@ -118,14 +118,50 @@ def get_top_chunks(query, chunk_embeddings, text_chunks):
|
|
| 118 |
# Print the top results
|
| 119 |
#print(top_results)
|
| 120 |
cleaned_chunks = preprocess_text(academic_tips_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
chunk_embeddings = create_embeddings(cleaned_chunks)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
#AI API being used
|
| 123 |
client= InferenceClient("openai/gpt-oss-20b")
|
| 124 |
#defining role of AI and user
|
| 125 |
|
| 126 |
def respond(message,history):
|
| 127 |
-
|
| 128 |
messages = [{"role": "assistant", "content": f"You are a friendly, helpful chatbot that gives academic advice to disadvantaged students about their education based on their question. You only answer in complete sentences with correct grammar, punctuation, and complete ideas. When you give advice, keep in mind the following information {information}"}]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
|
| 131 |
if history:
|
|
@@ -166,6 +202,8 @@ with gr.Blocks(
|
|
| 166 |
button_primary_background_fill='*secondary_500',
|
| 167 |
button_primary_background_fill_dark='*secondary_600'
|
| 168 |
)
|
|
|
|
|
|
|
| 169 |
) as demo:
|
| 170 |
|
| 171 |
gr.ChatInterface(
|
|
|
|
| 118 |
# Print the top results
|
| 119 |
#print(top_results)
|
| 120 |
cleaned_chunks = preprocess_text(academic_tips_text)
|
| 121 |
+
cleaned_chunks2= preprocess_text(extracurricular_ideas)
|
| 122 |
+
cleaned_chunks3= preprocess_text(time_management)
|
| 123 |
+
cleaned_chunks4= preprocess_text(financial_aid)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
chunk_embeddings = create_embeddings(cleaned_chunks)
|
| 127 |
+
chunk_embeddings2 = create_embeddings(cleaned_chunks2)
|
| 128 |
+
chunk_embeddings3 = create_embeddings(cleaned_chunks3)
|
| 129 |
+
chunk_embeddings4 = create_embeddings(cleaned_chunks4)
|
| 130 |
+
|
| 131 |
+
|
| 132 |
#AI API being used
|
| 133 |
client= InferenceClient("openai/gpt-oss-20b")
|
| 134 |
#defining role of AI and user
|
| 135 |
|
| 136 |
def respond(message,history):
|
| 137 |
+
topic_chunks=[]
|
| 138 |
messages = [{"role": "assistant", "content": f"You are a friendly, helpful chatbot that gives academic advice to disadvantaged students about their education based on their question. You only answer in complete sentences with correct grammar, punctuation, and complete ideas. When you give advice, keep in mind the following information {information}"}]
|
| 139 |
+
topic_chunks=[]
|
| 140 |
+
if chatbot_topic=="Academia":
|
| 141 |
+
information = get_top_chunks(message, chunk_embeddings, cleaned_chunks)
|
| 142 |
+
topic_chunks=get_top_chunks(message, chunk_embeddings, cleaned_chunks)
|
| 143 |
+
print(topic_chunks)
|
| 144 |
+
information= "/n".join(topic_chunks)
|
| 145 |
+
|
| 146 |
+
elif chatbot_topic=="Extracurriculars":
|
| 147 |
+
information = get_top_chunks(message, chunk_embeddings, cleaned_chunks2)
|
| 148 |
+
topic_chunks=get_top_chunks(message, chunk_embeddings, cleaned_chunks2)
|
| 149 |
+
print(topic_chunks)
|
| 150 |
+
information= "/n".join(topic_chunks)
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
elif chatbot_topic=="Time Management":
|
| 154 |
+
information = get_top_chunks(message, chunk_embeddings, cleaned_chunks3)
|
| 155 |
+
topic_chunks=get_top_chunks(message, chunk_embeddings, cleaned_chunks3)
|
| 156 |
+
print(topic_chunks)
|
| 157 |
+
information= "/n".join(topic_chunks)
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
elif chatbot_topic=="Financial Aid":
|
| 161 |
+
information = get_top_chunks(message, chunk_embeddings, cleaned_chunks4)
|
| 162 |
+
topic_chunks=get_top_chunks(message, chunk_embeddings, cleaned_chunks4)
|
| 163 |
+
print(topic_chunks)
|
| 164 |
+
information= "/n".join(topic_chunks)
|
| 165 |
|
| 166 |
|
| 167 |
if history:
|
|
|
|
| 202 |
button_primary_background_fill='*secondary_500',
|
| 203 |
button_primary_background_fill_dark='*secondary_600'
|
| 204 |
)
|
| 205 |
+
chatbot_topic=gr.CheckboxGroup(["Academia", "Extracurriculars", "Time Management", "Financial Aid"], label="Topics", info="What would you like advice about?")
|
| 206 |
+
|
| 207 |
) as demo:
|
| 208 |
|
| 209 |
gr.ChatInterface(
|