Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| import requests | |
| import os | |
| # Set your Groq API key (use Hugging Face secrets for deployment) | |
| GROQ_API_KEY = os.getenv("GROQ_API_KEY") | |
| GROQ_API_URL = "https://api.groq.com/openai/v1/chat/completions" | |
| st.set_page_config(page_title="EngGloss - Engineering Term Explainer", page_icon="π") | |
| st.title("π EngGloss: Engineering Term Explainer") | |
| st.write("Enter a technical term to get a beginner-friendly explanation.") | |
| term = st.text_input("π Enter an engineering term:", placeholder="e.g., Bernoulli's Principle") | |
| if st.button("Explain"): | |
| if not term.strip(): | |
| st.warning("Please enter a term.") | |
| else: | |
| with st.spinner("Generating explanation..."): | |
| prompt = f""" | |
| You are EngGloss, an expert engineering tutor who explains technical concepts in a beginner-friendly and structured way. | |
| Your task is to explain a single engineering term to a student or non-expert. Follow this exact format and keep the response concise and clear: | |
| π Term: {term} | |
| π Simple Explanation: Provide a brief explanation using plain language. Avoid jargon or complex phrases. Aim for clarity and simplicity. | |
| π§ Real-World Analogy: Use a relatable analogy from everyday life to help illustrate the concept intuitively. | |
| π Typical Formula: If the term is associated with a formula, show the most common version. Briefly explain what each variable means. If no formula exists, say: "There is no standard formula associated with this term." | |
| ποΈ Engineering Applications: List 2β3 branches of engineering where this term is often applied (e.g., civil, mechanical, electrical). Use bullet points. | |
| Respond in markdown format. Keep the tone helpful and clear, like youβre explaining to a college freshman. | |
| """ | |
| headers = { | |
| "Authorization": f"Bearer {GROQ_API_KEY}", | |
| "Content-Type": "application/json" | |
| } | |
| data = { | |
| "model": "mixtral-8x7b-32768", | |
| "messages": [ | |
| {"role": "system", "content": "You are EngGloss, an expert engineering tutor."}, | |
| {"role": "user", "content": prompt} | |
| ], | |
| "temperature": 0.7 | |
| } | |
| response = requests.post(GROQ_API_URL, headers=headers, json=data) | |
| if response.status_code == 200: | |
| result = response.json() | |
| explanation = result["choices"][0]["message"]["content"] | |
| st.markdown(explanation) | |
| else: | |
| st.error("Failed to get a response from Groq API.") | |
| st.code(response.text) | |