Spaces:
Runtime error
Runtime error
Nyha15 commited on
Commit ·
384ee0f
1
Parent(s): 51fa36a
Refactored
Browse files
app.py
CHANGED
|
@@ -199,7 +199,6 @@ class KnowledgeBase:
|
|
| 199 |
return [d.page_content for d in docs]
|
| 200 |
except Exception as e:
|
| 201 |
log_workflow("KB retrieve error", str(e))
|
| 202 |
-
# fallback
|
| 203 |
return getattr(self.data_collector, f"get_{self.domain}_data")(country)
|
| 204 |
|
| 205 |
# =======================================
|
|
@@ -215,6 +214,8 @@ class SpecialistAgent:
|
|
| 215 |
def run(self, query: str, country: str) -> str:
|
| 216 |
log_workflow(f"{self.name} analyzing", {"query": query[:50]})
|
| 217 |
knowledge = self.knowledge_base.retrieve(query, country)
|
|
|
|
|
|
|
| 218 |
prompt = f"""
|
| 219 |
As a specialist {self.name} for {country} students, answer:
|
| 220 |
|
|
@@ -222,7 +223,7 @@ QUERY:
|
|
| 222 |
{query}
|
| 223 |
|
| 224 |
KNOWLEDGE:
|
| 225 |
-
{
|
| 226 |
|
| 227 |
Provide detailed advice with names, steps, amounts.
|
| 228 |
Format with headings, bullets, and numbers.
|
|
@@ -353,33 +354,3 @@ class FinancePortal:
|
|
| 353 |
def handle(self, pid: str, query: str) -> str:
|
| 354 |
prof = self.get_profile(pid)
|
| 355 |
if not prof: return "Provide profile first."
|
| 356 |
-
clear_workflow_log()
|
| 357 |
-
resp = self.coordinator.run(query, prof)
|
| 358 |
-
return f"{resp}\n\n---\n\n{get_workflow_log()}"
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
def create_interface():
|
| 362 |
-
portal = FinancePortal()
|
| 363 |
-
def submit(q,country,visa,uni,fund,info):
|
| 364 |
-
pid = "user"
|
| 365 |
-
portal.register(pid, {"home_country":country,"visa_type":visa,"university":uni,"funding":fund,"additional_info":info})
|
| 366 |
-
return portal.handle(pid,q)
|
| 367 |
-
|
| 368 |
-
with gr.Blocks() as demo:
|
| 369 |
-
gr.Markdown("# International Student Finance Portal")
|
| 370 |
-
country = gr.Dropdown(["","India","China","Brazil","Other"], label="Home Country")
|
| 371 |
-
visa = gr.Dropdown(["","F-1","J-1","M-1","Other"], label="Visa Type")
|
| 372 |
-
uni = gr.Textbox(label="University")
|
| 373 |
-
fund = gr.Dropdown(["","Self/Family","Scholarship","TA/RA","Loan","Other"], label="Funding")
|
| 374 |
-
info = gr.Textbox(label="Additional Info")
|
| 375 |
-
query = gr.Textbox(label="Question", lines=4)
|
| 376 |
-
btn = gr.Button("Get Advice")
|
| 377 |
-
out = gr.Markdown()
|
| 378 |
-
btn.click(fn=submit, inputs=[query,country,visa,uni,fund,info], outputs=out)
|
| 379 |
-
return demo
|
| 380 |
-
|
| 381 |
-
if __name__ == "__main__":
|
| 382 |
-
print("Starting Finance Portal...")
|
| 383 |
-
get_api_key()
|
| 384 |
-
app = create_interface()
|
| 385 |
-
app.launch()
|
|
|
|
| 199 |
return [d.page_content for d in docs]
|
| 200 |
except Exception as e:
|
| 201 |
log_workflow("KB retrieve error", str(e))
|
|
|
|
| 202 |
return getattr(self.data_collector, f"get_{self.domain}_data")(country)
|
| 203 |
|
| 204 |
# =======================================
|
|
|
|
| 214 |
def run(self, query: str, country: str) -> str:
|
| 215 |
log_workflow(f"{self.name} analyzing", {"query": query[:50]})
|
| 216 |
knowledge = self.knowledge_base.retrieve(query, country)
|
| 217 |
+
# Pre-build knowledge section to avoid backslashes in f-string
|
| 218 |
+
knowledge_section = "\n".join(f"- {item}" for item in knowledge)
|
| 219 |
prompt = f"""
|
| 220 |
As a specialist {self.name} for {country} students, answer:
|
| 221 |
|
|
|
|
| 223 |
{query}
|
| 224 |
|
| 225 |
KNOWLEDGE:
|
| 226 |
+
{knowledge_section}
|
| 227 |
|
| 228 |
Provide detailed advice with names, steps, amounts.
|
| 229 |
Format with headings, bullets, and numbers.
|
|
|
|
| 354 |
def handle(self, pid: str, query: str) -> str:
|
| 355 |
prof = self.get_profile(pid)
|
| 356 |
if not prof: return "Provide profile first."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|