SyedWaqad commited on
Commit
1feae15
·
verified ·
1 Parent(s): ab200cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -42
app.py CHANGED
@@ -1,8 +1,5 @@
1
- import streamlit as st
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
- # Streamlit UI
46
  # -------------------------
47
- st.title("EngGloss")
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
- st.error("Please enter your Groq API key.")
58
- elif not term.strip():
59
- st.error("Please enter an engineering term.")
60
- else:
61
- with st.spinner("Generating explanation..."):
62
- url = "https://api.groq.com/openai/v1/chat/completions"
63
-
64
- headers = {
65
- "Authorization": f"Bearer {api_key}",
66
- "Content-Type": "application/json"
67
- }
68
-
69
- payload = {
70
- "model": "llama3-70b-8192",
71
- "messages": [
72
- {"role": "system", "content": SYSTEM_PROMPT},
73
- {"role": "user", "content": term}
74
- ],
75
- "temperature": 0.2
76
- }
77
-
78
- response = requests.post(url, headers=headers, json=payload)
79
-
80
- if response.status_code == 200:
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"]