Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,5 @@
|
|
| 1 |
-
import
|
| 2 |
import requests
|
| 3 |
-
import json
|
| 4 |
-
|
| 5 |
-
st.set_page_config(page_title="EngGloss – Engineering Term Explainer")
|
| 6 |
|
| 7 |
# -------------------------
|
| 8 |
# EngGloss System Prompt
|
|
@@ -42,43 +39,31 @@ USER INPUT: The engineering term to explain.
|
|
| 42 |
"""
|
| 43 |
|
| 44 |
# -------------------------
|
| 45 |
-
#
|
| 46 |
# -------------------------
|
| 47 |
-
|
| 48 |
-
st.write("Enter any engineering term and get a simple structured explanation.")
|
| 49 |
-
|
| 50 |
-
# Groq API key input
|
| 51 |
-
api_key = st.text_input("Enter your Groq API Key", type="password")
|
| 52 |
-
|
| 53 |
-
term = st.text_input("Engineering Term")
|
| 54 |
-
|
| 55 |
-
if st.button("Explain"):
|
| 56 |
if not api_key:
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
result = response.json()["choices"][0]["message"]["content"]
|
| 82 |
-
st.markdown(result)
|
| 83 |
-
else:
|
| 84 |
-
st.error(f"Error: {response.text}")
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
import requests
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
# -------------------------
|
| 5 |
# EngGloss System Prompt
|
|
|
|
| 39 |
"""
|
| 40 |
|
| 41 |
# -------------------------
|
| 42 |
+
# Function to call Groq API
|
| 43 |
# -------------------------
|
| 44 |
+
def explain_term(api_key, term):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
if not api_key:
|
| 46 |
+
return "Error: Please provide your Groq API key."
|
| 47 |
+
if not term or not term.strip():
|
| 48 |
+
return "Error: Please enter an engineering term."
|
| 49 |
+
|
| 50 |
+
url = "https://api.groq.com/openai/v1/chat/completions"
|
| 51 |
+
|
| 52 |
+
headers = {
|
| 53 |
+
"Authorization": f"Bearer {api_key}",
|
| 54 |
+
"Content-Type": "application/json"
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
payload = {
|
| 58 |
+
"model": "llama3-70b-8192",
|
| 59 |
+
"messages": [
|
| 60 |
+
{"role": "system", "content": SYSTEM_PROMPT},
|
| 61 |
+
{"role": "user", "content": term}
|
| 62 |
+
],
|
| 63 |
+
"temperature": 0.2
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
response = requests.post(url, headers=headers, json=payload)
|
| 67 |
+
|
| 68 |
+
if response.status_code == 200:
|
| 69 |
+
return response.json()["choices"][0]["message"]["content"]
|
|
|
|
|
|
|
|
|
|
|
|