Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ from flask_cors import CORS
|
|
| 3 |
import os, json, httpx
|
| 4 |
|
| 5 |
app = Flask(__name__)
|
| 6 |
-
CORS(app
|
| 7 |
|
| 8 |
OPENROUTER_API_KEY = os.getenv("API_KEYS")
|
| 9 |
|
|
@@ -19,15 +19,18 @@ def _headers():
|
|
| 19 |
"X-Title": "Minimal Streaming Test",
|
| 20 |
}
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
| 23 |
"stream": True,
|
| 24 |
"messages": [{"role":"system","content":"""
|
| 25 |
-
|
| 26 |
-
|
| 27 |
- Output exactly three parts:
|
| 28 |
1) Title line: “### {TOPIC}”
|
|
|
|
| 29 |
2) Paragraph 1 (English only): 1–2 conversational sentences, 15–35 words, pure facts, no questions, no metaphors.
|
| 30 |
-
3)
|
| 31 |
4) Paragraph 2 (Tanglish): ONE continuous paragraph, no line breaks, no bullets, no emojis, no bold/italics. Length target: 110–160 words.
|
| 32 |
- Total target length (title + para1 + para2): 160–220 words.
|
| 33 |
- Do not add any extra sections or commentary.
|
|
@@ -55,15 +58,24 @@ Topic guardrail examples (apply when relevant):
|
|
| 55 |
- If {TOPIC} = “what is photosynthesis?” → Early in Paragraph 2, include: plants use sunlight, water, and carbon dioxide to make food (glucose) and release oxygen.
|
| 56 |
Self‑check (do internally; rewrite once if violated):
|
| 57 |
- Title starts with “###”.
|
|
|
|
| 58 |
- Paragraph 1: 15–35 words, English only, no questions/metaphors.
|
| 59 |
-
-
|
| 60 |
- Paragraph 2: single continuous block; A→B→C→D order; exactly two examples with correct starters; ends with ONE check‑in question.
|
| 61 |
- No formal Tamil or textbook openers.
|
| 62 |
- Sounds like a human WhatsApp voice note by a Chennai teacher.
|
| 63 |
Generate the output now for this topic:
|
| 64 |
{TOPIC}
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
"top_p":0.9,
|
| 68 |
"max_tokens": 999,
|
| 69 |
}
|
|
@@ -128,7 +140,7 @@ def ask():
|
|
| 128 |
print(prompt)
|
| 129 |
else:
|
| 130 |
if mode=="Simple Learn":
|
| 131 |
-
prompt="TOPIC : "+q
|
| 132 |
|
| 133 |
elif mode=="Learn Deeper":
|
| 134 |
prompt=q2lang+"Explain this concept in details Mode: give a detailed and complete explanation including definitions, conceptual breakdowns, real-life applications, multiple examples, and step-by-step working. Assume I am a beginner but curious to understand deeply. Make it structured, clear, and fully educational — like a textbook with guidance. words limits 200-250"
|
|
|
|
| 3 |
import os, json, httpx
|
| 4 |
|
| 5 |
app = Flask(__name__)
|
| 6 |
+
CORS(app)
|
| 7 |
|
| 8 |
OPENROUTER_API_KEY = os.getenv("API_KEYS")
|
| 9 |
|
|
|
|
| 19 |
"X-Title": "Minimal Streaming Test",
|
| 20 |
}
|
| 21 |
|
| 22 |
+
def _payload(q: str):
|
| 23 |
+
return {
|
| 24 |
+
"model": "meta-llama/llama-4-maverick-17b-128e-instruct",
|
| 25 |
"stream": True,
|
| 26 |
"messages": [{"role":"system","content":"""
|
| 27 |
+
You are Isa, a warm 28‑year‑old AI English tutor for Tamil-speaking kids and parents in 2025. Speak modern Chennai Tanglish like a WhatsApp voice note. Keep sentences short (6–12 words), vary rhythm, and stay casual and empathetic. Use Tamil connectors; keep technical terms in English. Never use literary Tamil or textbook tone.
|
| 28 |
+
Task and output format (strict):
|
| 29 |
- Output exactly three parts:
|
| 30 |
1) Title line: “### {TOPIC}”
|
| 31 |
+
[strictly no line gap between title line and paragraph 1]
|
| 32 |
2) Paragraph 1 (English only): 1–2 conversational sentences, 15–35 words, pure facts, no questions, no metaphors.
|
| 33 |
+
3) strictly one line gap between paragraph 1 and paragraph 2
|
| 34 |
4) Paragraph 2 (Tanglish): ONE continuous paragraph, no line breaks, no bullets, no emojis, no bold/italics. Length target: 110–160 words.
|
| 35 |
- Total target length (title + para1 + para2): 160–220 words.
|
| 36 |
- Do not add any extra sections or commentary.
|
|
|
|
| 58 |
- If {TOPIC} = “what is photosynthesis?” → Early in Paragraph 2, include: plants use sunlight, water, and carbon dioxide to make food (glucose) and release oxygen.
|
| 59 |
Self‑check (do internally; rewrite once if violated):
|
| 60 |
- Title starts with “###”.
|
| 61 |
+
[strictly no line gap between title and paragraph 1]
|
| 62 |
- Paragraph 1: 15–35 words, English only, no questions/metaphors.
|
| 63 |
+
- strictly one line gap between paragraph 1 and paragraph 2
|
| 64 |
- Paragraph 2: single continuous block; A→B→C→D order; exactly two examples with correct starters; ends with ONE check‑in question.
|
| 65 |
- No formal Tamil or textbook openers.
|
| 66 |
- Sounds like a human WhatsApp voice note by a Chennai teacher.
|
| 67 |
Generate the output now for this topic:
|
| 68 |
{TOPIC}
|
| 69 |
+
output format :
|
| 70 |
+
#topic
|
| 71 |
+
para1
|
| 72 |
+
para2
|
| 73 |
+
example :
|
| 74 |
+
### what is current?
|
| 75 |
+
Current is the flow of electric charge, measured in amperes. It is the rate at which electric charge flows through a conductor, such as a wire, and is essential for powering devices.
|
| 76 |
+
Current னு சொல்றது wire ல electron-ங்க move ஆகுற flow தான், அதாவது electric charge conductor ல பாய்றது. சரி, phone charging எடுத்துக்கலாம், battery ல இருந்து phone-க்கு current பாய்றுது, அப்போ power கிடைக்குது. அதனால, current இல்லனா phone charge ஆகாது, ஏன்னா electron flow இல்ல. உதாரணமா, நம்ம வீட்ல wire-ல current பாய்றுது, அதனால தான் light, fan எல்லாம் வேலை செய்யுது. யோசிச்சு பாருங்க, நம்ம ஊர்ல பஸ் ல people ஏறுறது, பஸ் move ஆகுற மாதிரி, wire ல electron-ங்க move ஆகுது. இவ்ளோதான், clear ஆ இருக்கா?
|
| 77 |
+
"""},{"role": "user", "content": q}],
|
| 78 |
+
"temperature": 0.7,
|
| 79 |
"top_p":0.9,
|
| 80 |
"max_tokens": 999,
|
| 81 |
}
|
|
|
|
| 140 |
print(prompt)
|
| 141 |
else:
|
| 142 |
if mode=="Simple Learn":
|
| 143 |
+
prompt="{TOPIC} : "+q
|
| 144 |
|
| 145 |
elif mode=="Learn Deeper":
|
| 146 |
prompt=q2lang+"Explain this concept in details Mode: give a detailed and complete explanation including definitions, conceptual breakdowns, real-life applications, multiple examples, and step-by-step working. Assume I am a beginner but curious to understand deeply. Make it structured, clear, and fully educational — like a textbook with guidance. words limits 200-250"
|