|
|
import streamlit as st |
|
|
import requests |
|
|
import os |
|
|
|
|
|
|
|
|
GROQ_API_KEY = os.getenv("GROQ_API_KEY") |
|
|
GROQ_API_URL = "https://api.groq.com/openai/v1/chat/completions" |
|
|
|
|
|
HEADERS = { |
|
|
"Authorization": f"Bearer {GROQ_API_KEY}", |
|
|
"Content-Type": "application/json" |
|
|
} |
|
|
|
|
|
SYSTEM_PROMPT = """ |
|
|
You are EngGloss, an expert engineering tutor who explains technical terms in a way that's simple and clear for beginners. |
|
|
|
|
|
When given a single engineering term, respond with structured output in the following exact format using emojis and section titles: |
|
|
|
|
|
π **Term**: <term> |
|
|
|
|
|
π **Simple Explanation**: Provide a concise, beginner-friendly explanation of the term. Avoid technical jargon or complicated language. |
|
|
|
|
|
π§ **Real-World Analogy**: Explain the concept using a relatable analogy from everyday life that makes it easier to understand. |
|
|
|
|
|
π **Typical Formula**: If a standard formula exists for this term, present it. Briefly explain what each variable represents. If no common formula exists, say: "There is no widely accepted formula for this term." |
|
|
|
|
|
ποΈ **Engineering Applications**: List 2β3 practical engineering applications where this term is used. Be specific. For example, if the term is "Ohmβs Law", an application could be "Designing electric circuits in household appliances" or "Calculating resistor values in LED lighting systems". |
|
|
|
|
|
Keep your entire response short, clear, and helpful for a first-year engineering student or a curious beginner. Do not add any extra commentary or introduction. |
|
|
""" |
|
|
|
|
|
|
|
|
def query_groq(term): |
|
|
payload = { |
|
|
"model": "llama3-8b-8192", |
|
|
"messages": [ |
|
|
{"role": "system", "content": SYSTEM_PROMPT}, |
|
|
{"role": "user", "content": f"{term}"} |
|
|
], |
|
|
"temperature": 0.7 |
|
|
} |
|
|
response = requests.post(GROQ_API_URL, headers=HEADERS, json=payload) |
|
|
if response.status_code == 200: |
|
|
return response.json()['choices'][0]['message']['content'] |
|
|
else: |
|
|
return f"β οΈ Error: {response.status_code} - {response.text}" |
|
|
|
|
|
|
|
|
st.set_page_config(page_title="EngGloss β Engineering Term Explainer", page_icon="π") |
|
|
st.title("π EngGloss: Engineering Term Explainer") |
|
|
|
|
|
term = st.text_input("Enter an engineering term:", placeholder="e.g., Ohmβs Law, Bernoulli Principle") |
|
|
|
|
|
if term: |
|
|
with st.spinner("Generating explanation..."): |
|
|
output = query_groq(term) |
|
|
st.markdown(output) |
|
|
|