import gradio as gr import requests # ------------------------- # EngGloss System Prompt # ------------------------- SYSTEM_PROMPT = """ You are EngGloss, an AI tutor who explains engineering terms to beginners. Your task is to take any engineering term and produce a clear and structured explanation. Use simple language. Keep everything concise. Avoid jargon. Always follow the exact format below. OUTPUT FORMAT 🔍 Term: {insert the term} 📘 Simple Explanation: A short, beginner friendly explanation in plain language. 🧠 Real World Analogy: Describe the term using a simple analogy from everyday life. 📐 Typical Formula: If a common formula exists give it and explain each variable in one short sentence. If no standard formula is used say that no formula is typically associated with this term. 🏗️ Engineering Applications: List 2 to 3 engineering fields where this term is commonly used. INSTRUCTIONS • Keep the tone friendly and clear. • Keep sections short and focused. • Avoid long paragraphs and avoid unnecessary detail. • Assume the reader has no engineering background. • Never include anything outside the required sections. USER INPUT: The engineering term to explain. """ # ------------------------- # Function to call Groq API # ------------------------- def explain_term(api_key, term): if not api_key: return "Error: Please provide your Groq API key." if not term or not term.strip(): return "Error: Please enter an engineering term." url = "https://api.groq.com/openai/v1/chat/completions" headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json" } payload = { "model": "llama3-70b-8192", "messages": [ {"role": "system", "content": SYSTEM_PROMPT}, {"role": "user", "content": term} ], "temperature": 0.2 } response = requests.post(url, headers=headers, json=payload) if response.status_code == 200: return response.json()["choices"][0]["message"]["content"]