import streamlit as st import pandas as pd import requests import os # ---------------------------- # Configuration # ---------------------------- st.set_page_config(page_title="Instrumentation Standards AI Assistant", layout="wide") # ---------------------------- # Load Data # ---------------------------- @st.cache_data def load_data(): df = pd.read_excel("data.xlsx", engine='openpyxl') return df df = load_data() # ---------------------------- # GROQ API Summarizer # ---------------------------- GROQ_API_KEY = os.getenv("Standardssearch") # Set this in your environment or .streamlit/secrets.toml def summarize_with_groq(text, model="llama3-70b-8192"): url = "https://api.groq.com/openai/v1/chat/completions" headers = { "Authorization": f"Bearer {GROQ_API_KEY}", "Content-Type": "application/json" } payload = { "model": model, "messages": [ {"role": "system", "content": "You are a helpful assistant summarizing industrial standards for instrumentation and control engineers."}, {"role": "user", "content": f"Summarize the following technical standard for a professional audience:\n\n{text}"} ], "temperature": 0.5 } response = requests.post(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}" # ---------------------------- # UI Layout # ---------------------------- st.title("📘 Instrumentation & Control Engineering Standards") st.markdown("This app helps Instrumentation & Control Engineers search and understand global engineering standards.") st.markdown("**Standards included:** ANSI, API, ASME, ASTM, BS, IEC, ISA, ISO, MSS, NACE, NAMUR, NFPA, PIP, EN, and more.") # Search Filters st.subheader("🔍 Search for Industrial Standards") col1, col2 = st.columns(2) with col1: entity_input = st.text_input("Enter Standard Entity").strip() with col2: name_input = st.text_input("Enter Standard Name").strip() # Filtered Results if entity_input or name_input: filtered_df = df[ df["Standards Entity"].str.contains(entity_input, case=False, na=False) & df["Standard Name"].str.contains(name_input, case=False, na=False) ] if not filtered_df.empty: st.success(f"✅ Found {len(filtered_df)} matching standard(s). Click to expand.") for index, row in filtered_df.iterrows(): with st.expander(f"📘 {row['Standard Name']}"): st.markdown(f"**Entity:** {row['Standards Entity']}") st.markdown(f"**Description:** {row['Description']}") if st.button("Summarize with AI", key=f"summarize_{index}"): with st.spinner("Querying GROQ model for summary..."): summary = summarize_with_groq(row["Description"]) st.markdown("### ✨ AI Summary") st.write(summary) else: st.warning("No matching standards found.") else: st.info("Enter at least one search term to begin.") # Footer st.markdown("---") st.caption("Built with ❤️ for Control & Instrumentation Engineers | Powered by GROQ + Streamlit")