Spaces:
Sleeping
Sleeping
Update app.py
Browse files5 unmodified lines6789101148 unmodified lines606162636465666724 unmodified lines92939495969798991001011025 unmodified linesDEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"# --- provider selection (HF serverless text-generation by default; optional Groq) ---def select_model():provider = os.getenv("PROVIDER", "hf").lower()48 unmodified lineschat = self.hf.chat_completion(model=model,messages=[{"role": "user", "content": prompt}],max_tokens=128,temperature=0.2,)return chat.choices[0].message["content"].strip()raise24 unmodified linesif ctx:prompt += f"\nContext:\n{ctx[:2000]}\n"ans = self._llm(prompt).strip().splitlines()[0]# strip common wrappers just in casefor pre in ("final answer:", "answer:", "final:", "prediction:"):if ans.lower().startswith(pre): ans = ans[len(pre):].strip()return ansdef run_and_submit_all( profile: gr.OAuthProfile | None):"""5 unmodified lines6789101112131415161718192021222348 unmodified lines7273747576777824 unmodified lines1031041051061071081091105 unmodified linesDEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"def format_final_answer(q: str, raw: str) -> str:text = raw.strip().splitlines()[0]if "how many" in q.lower():m = re.search(r"\d+", text)if m:return m.group(0)# As a safeguard, also strip common wrappers:for pre in ("final answer:", "answer:", "final:", "prediction:"):if text.lower().startswith(pre):text = text[len(pre):].strip()return text# --- provider selection (HF serverless text-generation by default; optional Groq) ---def select_model():provider = os.getenv("PROVIDER", "hf").lower()48 unmodified lineschat = self.hf.chat_completion(model=model,messages=[{"role": "user", "content": prompt}],temperature=0.0, max_tokens=16, top_p=1.0)return chat.choices[0].message["content"].strip()raise24 unmodified linesif ctx:prompt += f"\nContext:\n{ctx[:2000]}\n"raw = self._llm(prompt)return format_final_answer(question, raw)def run_and_submit_all( profile: gr.OAuthProfile | None):"""
app.py+15-7