Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
from groq import Groq
|
| 4 |
+
|
| 5 |
+
# Get API Key
|
| 6 |
+
api_key = os.getenv("GROQ_API_KEY")
|
| 7 |
+
|
| 8 |
+
# Initialize Groq client
|
| 9 |
+
client = Groq(api_key=api_key) if api_key else None
|
| 10 |
+
|
| 11 |
+
# Streamlit UI
|
| 12 |
+
st.set_page_config(page_title="🧪 ChemEng AI Assistant", page_icon="🧪")
|
| 13 |
+
st.title("🧪 Chemical Engineering Equipment Sizing Assistant")
|
| 14 |
+
|
| 15 |
+
st.markdown("""
|
| 16 |
+
Ask any question about chemical process equipment sizing and get AI-powered answers based on domain knowledge.
|
| 17 |
+
|
| 18 |
+
**Try examples like:**
|
| 19 |
+
- `What size of distillation column is used for 5000 kg/hr ethanol separation?`
|
| 20 |
+
- `Size a shell-and-tube heat exchanger for 1 MW heat duty.`
|
| 21 |
+
- `Suggest the volume of a CSTR with 1-hour residence time at 2000 L/hr.`
|
| 22 |
+
""")
|
| 23 |
+
|
| 24 |
+
# User Input
|
| 25 |
+
query = st.text_area("💬 Enter your question:", height=150)
|
| 26 |
+
|
| 27 |
+
# Model Selector (Only supported by Groq)
|
| 28 |
+
model = st.selectbox("🔍 Choose a model:", [
|
| 29 |
+
"llama-3.1-8b-instant",
|
| 30 |
+
"llama-3.3-70b-versatile",
|
| 31 |
+
"openai/gpt-oss-120b"
|
| 32 |
+
])
|
| 33 |
+
|
| 34 |
+
# Process the query
|
| 35 |
+
if st.button("🚀 Get Response"):
|
| 36 |
+
if not api_key:
|
| 37 |
+
st.error("🚨 Groq API Key not found. Set the GROQ_API_KEY in your environment.")
|
| 38 |
+
elif not query.strip():
|
| 39 |
+
st.warning("⚠️ Please enter a question.")
|
| 40 |
+
else:
|
| 41 |
+
with st.spinner("Generating response..."):
|
| 42 |
+
try:
|
| 43 |
+
chat_completion = client.chat.completions.create(
|
| 44 |
+
model=model,
|
| 45 |
+
messages=[
|
| 46 |
+
{
|
| 47 |
+
"role": "system",
|
| 48 |
+
"content": (
|
| 49 |
+
"You are a senior chemical engineer. Answer user questions about equipment sizing, "
|
| 50 |
+
"design rules, and heuristics clearly and concisely. Provide real-world estimates based on "
|
| 51 |
+
"chemical engineering practices."
|
| 52 |
+
)
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
"role": "user",
|
| 56 |
+
"content": query
|
| 57 |
+
}
|
| 58 |
+
]
|
| 59 |
+
)
|
| 60 |
+
response = chat_completion.choices[0].message.content
|
| 61 |
+
st.success("✅ Answer:")
|
| 62 |
+
st.markdown(response)
|
| 63 |
+
|
| 64 |
+
except Exception as e:
|
| 65 |
+
st.error(f"❌ Error: {str(e)}")
|