Hikmatk commited on
Commit
2cdf532
Β·
verified Β·
1 Parent(s): a9ae79a

Create app.py

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