Spaces:
Sleeping
Sleeping
GAJJALAASHOKKUMARREDDY commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -310,14 +310,14 @@ def detect_intent(prompt: str) -> str:
|
|
| 310 |
|
| 311 |
# Map emotion labels to intents
|
| 312 |
emotion_to_intent = {
|
| 313 |
-
"sadness": "
|
| 314 |
-
"joy": "
|
| 315 |
-
"love": "
|
| 316 |
-
"anger": "
|
| 317 |
-
"fear": "
|
| 318 |
-
"surprise": "
|
| 319 |
-
"neutral": "
|
| 320 |
-
"optimism": "
|
| 321 |
}
|
| 322 |
|
| 323 |
for emotion, intent in emotion_to_intent.items():
|
|
@@ -470,56 +470,31 @@ async def generate_reply_stream(prompt: str, files: List[UploadFile], max_tokens
|
|
| 470 |
try:
|
| 471 |
# Construct final prompt for Phi-3.5
|
| 472 |
system_msg = (
|
| 473 |
-
'''# GAKR AI Assistant
|
| 474 |
-
|
| 475 |
-
##
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
##
|
| 485 |
-
**Simple Questions**
|
| 486 |
-
π― **Answer** β Brief explanation (1β2 lines)
|
| 487 |
-
**Complex Topics**
|
| 488 |
π― **Core Answer**
|
| 489 |
β’ What: Key facts
|
| 490 |
-
β’ How:
|
| 491 |
β’ Why: Rationale
|
| 492 |
-
β’ π Recommendations
|
| 493 |
-
β’ β οΈ Risks
|
| 494 |
-
β’ π Predictions
|
| 495 |
-
##
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
π§ Technical details
|
| 502 |
-
π Opportunities
|
| 503 |
-
β
Advantages
|
| 504 |
-
β Limitations
|
| 505 |
-
## Quality Principles
|
| 506 |
-
β’ Accuracy > confidence
|
| 507 |
-
β’ Clarity > verbosity
|
| 508 |
-
β’ Practicality > theory
|
| 509 |
-
β’ Honest about uncertainty
|
| 510 |
-
β’ Avoid speculation when evidence is weak
|
| 511 |
-
Additional context : Present information as current understanding without referencing search mechanics;
|
| 512 |
-
prioritize verifiable and recent info while acknowledging uncertainty when needed.
|
| 513 |
-
## Anti-Rules
|
| 514 |
-
β No βAs an AIβ¦β
|
| 515 |
-
β No filler or fluff
|
| 516 |
-
β No forced structure when unnecessary
|
| 517 |
-
β No pretending certainty when unsure
|
| 518 |
-
## Tone
|
| 519 |
-
Confident, clear, actionable.
|
| 520 |
-
Prioritize usefulness and real-world value.
|
| 521 |
-
Always Act as a GAKR Ai
|
| 522 |
-
**Remember**: Direct answer first β structure when helpful β actionable takeaways.
|
| 523 |
'''
|
| 524 |
)
|
| 525 |
context_parts = []
|
|
@@ -531,7 +506,6 @@ Always Act as a GAKR Ai
|
|
| 531 |
context = "\n\n".join(context_parts) if context_parts else "No additional context provided."
|
| 532 |
|
| 533 |
final_user_content = f"""User Query: {prompt}
|
| 534 |
-
Intent: {intent_label}
|
| 535 |
Additional Context: {context}
|
| 536 |
**Note**: Provide concise answers. Do not reveal or simulate chain-of-thought; give only the final response."""
|
| 537 |
|
|
@@ -566,14 +540,12 @@ Additional Context: {context}
|
|
| 566 |
# Generation parameters - TIGHTER FOR BETTER RESPONSES
|
| 567 |
generation_kwargs = dict(
|
| 568 |
**inputs,
|
| 569 |
-
max_new_tokens=250,
|
| 570 |
-
temperature=0.2,
|
| 571 |
do_sample=True,
|
| 572 |
top_p=0.9,
|
| 573 |
top_k=50,
|
| 574 |
-
repetition_penalty=1.3,
|
| 575 |
-
no_repeat_ngram_size=3,
|
| 576 |
-
length_penalty=0.8,
|
| 577 |
pad_token_id=phi_tokenizer.eos_token_id,
|
| 578 |
eos_token_id=phi_tokenizer.eos_token_id,
|
| 579 |
streamer=request_streamer,
|
|
|
|
| 310 |
|
| 311 |
# Map emotion labels to intents
|
| 312 |
emotion_to_intent = {
|
| 313 |
+
"sadness": "general_query",
|
| 314 |
+
"joy": "positive_query",
|
| 315 |
+
"love": "creative_request",
|
| 316 |
+
"anger": "technical_query",
|
| 317 |
+
"fear": "help_request",
|
| 318 |
+
"surprise": "question_query",
|
| 319 |
+
"neutral": "general_chat",
|
| 320 |
+
"optimism": "positive_query"
|
| 321 |
}
|
| 322 |
|
| 323 |
for emotion, intent in emotion_to_intent.items():
|
|
|
|
| 470 |
try:
|
| 471 |
# Construct final prompt for Phi-3.5
|
| 472 |
system_msg = (
|
| 473 |
+
'''# GAKR AI Assistant
|
| 474 |
+
You are GAKR AI: a highβperformance, adaptive assistant.
|
| 475 |
+
## Core rules
|
| 476 |
+
- Start with a direct answer or key insight (π― + bold if helpful).
|
| 477 |
+
- Keep simple replies short (1β3 sentences); use structure only when useful.
|
| 478 |
+
- Adapt depth, tone, and format to query complexity and user level.
|
| 479 |
+
- If ambiguous, ask 1 focused clarification question.
|
| 480 |
+
- Prefer verifiable facts and stable fundamentals; admit uncertainty when evidence is weak.
|
| 481 |
+
- Never mention: βAs an AIβ¦β, training data, cutoff dates, or search mechanics.
|
| 482 |
+
π― Key insight, π analysis/recommendations, β οΈ risks, π trends, π‘ tips, π§ technical,
|
| 483 |
+
π opportunities, β
pros, β cons β use only when they clearly improve clarity or scannability.
|
| 484 |
+
## Complex topics (when helpful)
|
|
|
|
|
|
|
|
|
|
| 485 |
π― **Core Answer**
|
| 486 |
β’ What: Key facts
|
| 487 |
+
β’ How: Steps
|
| 488 |
β’ Why: Rationale
|
| 489 |
+
β’ π Recommendations
|
| 490 |
+
β’ β οΈ Risks
|
| 491 |
+
β’ π Predictions (only when trendβinsight is relevant)
|
| 492 |
+
## Quality & Antiβrules
|
| 493 |
+
- Accuracy > confidence; clarity > verbosity; practicality > theory.
|
| 494 |
+
- Tone: Confident, clear, actionable; maximize realβworld value.
|
| 495 |
+
- β No filler, no fluff, no forced structure, no fake certainty.
|
| 496 |
+
- Always: Direct answer first β structure when helpful β actionable takeaways.
|
| 497 |
+
- Act as GAKR AI at all times.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 498 |
'''
|
| 499 |
)
|
| 500 |
context_parts = []
|
|
|
|
| 506 |
context = "\n\n".join(context_parts) if context_parts else "No additional context provided."
|
| 507 |
|
| 508 |
final_user_content = f"""User Query: {prompt}
|
|
|
|
| 509 |
Additional Context: {context}
|
| 510 |
**Note**: Provide concise answers. Do not reveal or simulate chain-of-thought; give only the final response."""
|
| 511 |
|
|
|
|
| 540 |
# Generation parameters - TIGHTER FOR BETTER RESPONSES
|
| 541 |
generation_kwargs = dict(
|
| 542 |
**inputs,
|
| 543 |
+
max_new_tokens=250,
|
| 544 |
+
temperature=0.2,
|
| 545 |
do_sample=True,
|
| 546 |
top_p=0.9,
|
| 547 |
top_k=50,
|
| 548 |
+
repetition_penalty=1.3, # Keep this
|
|
|
|
|
|
|
| 549 |
pad_token_id=phi_tokenizer.eos_token_id,
|
| 550 |
eos_token_id=phi_tokenizer.eos_token_id,
|
| 551 |
streamer=request_streamer,
|