Hikmatk commited on
Commit
d9c74ad
Β·
verified Β·
1 Parent(s): e5a3380

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -0
app.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import os
4
+
5
+ # Set your Groq API key
6
+ GROQ_API_KEY = os.getenv("GROQ_API_KEY") # or use st.secrets["GROQ_API_KEY"]
7
+ GROQ_API_URL = "https://api.groq.com/openai/v1/chat/completions"
8
+
9
+ # Page config
10
+ st.set_page_config(page_title="EngGloss - Engineering Term Explainer", page_icon="πŸ“˜")
11
+
12
+ st.title("πŸ“˜ EngGloss: Engineering Term Explainer")
13
+ st.write("Enter a technical term to get a beginner-friendly explanation.")
14
+
15
+ # User input
16
+ term = st.text_input("πŸ” Enter an engineering term:", placeholder="e.g., Bernoulli's Principle")
17
+
18
+ # Button to trigger explanation
19
+ if st.button("Explain"):
20
+ if not term.strip():
21
+ st.warning("Please enter a term.")
22
+ else:
23
+ with st.spinner("Generating explanation..."):
24
+ # Build the prompt
25
+ prompt = f"""
26
+ You are EngGloss, an expert engineering tutor who explains technical concepts in a beginner-friendly and structured way.
27
+
28
+ 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:
29
+
30
+ πŸ” Term: {term}
31
+
32
+ πŸ“˜ Simple Explanation: Provide a brief explanation using plain language. Avoid jargon or complex phrases. Aim for clarity and simplicity.
33
+
34
+ 🧠 Real-World Analogy: Use a relatable analogy from everyday life to help illustrate the concept intuitively.
35
+
36
+ πŸ“ 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."
37
+
38
+ πŸ—οΈ Engineering Applications: List 2–3 branches of engineering where this term is often applied (e.g., civil, mechanical, electrical). Use bullet points.
39
+
40
+ Respond in markdown format. Keep the tone helpful and clear, like you’re explaining to a college freshman.
41
+ """
42
+
43
+ # Make Groq API request
44
+ headers = {
45
+ "Authorization": f"Bearer {GROQ_API_KEY}",
46
+ "Content-Type": "application/json"
47
+ }
48
+
49
+ data = {
50
+ "model": "mixtral-8x7b-32768", # or another supported model
51
+ "messages": [
52
+ {"role": "system", "content": "You are EngGloss, an expert engineering tutor."},
53
+ {"role": "user", "content": prompt}
54
+ ],
55
+ "temperature": 0.7
56
+ }
57
+
58
+ response = requests.post(GROQ_API_URL, headers=headers, json=data)
59
+
60
+ if response.status_code == 200:
61
+ result = response.json()
62
+ explanation = result["choices"][0]["message"]["content"]
63
+ st.markdown(explanation)
64
+ else:
65
+ st.error("Failed to get a response from Groq API.")
66
+ st.code(response.text)