tbaig1605's picture
Update app.py
2a3700a verified
import streamlit as st
import os
import requests
st.set_page_config(page_title="Stakeholder Behaviour AI", layout="wide")
st.title("📊 AI Assistant for Stakeholder Behaviour in Civil Projects")
# Sidebar input
st.sidebar.header("Enter Situation / Stakeholder Statement")
user_input = st.sidebar.text_area("Describe the situation", height=150)
api_key = os.environ.get("apikeygpt")
if not api_key:
st.error("GROQ_API_KEY environment variable not set in Hugging Face Space.")
else:
if st.sidebar.button("Analyze Situation"):
with st.spinner("Analyzing stakeholder behaviour..."):
prompt = f"""
You are an expert AI in predicting stakeholder behaviour in civil engineering projects.
A user will give you a technical term, a stakeholder statement, or a project situation.
Your main job is to **predict stakeholder behaviours in the given situation,
describe likely consequences of those behaviours, identify the drivers
behind those behaviours, and provide strategies to influence them positively.**
Structure your report with the following sections:
1️⃣ Explanation
2️⃣ Past Cases & Lessons Learned
3️⃣ Stakeholder Classification
4️⃣ Predicted Stakeholder Behaviours (with probability / likelihood)
5️⃣ Behavioural Drivers (reasons for those behaviours)
6️⃣ Behaviour Change Triggers (what could shift the behaviour)
7️⃣ Potential Consequences of These Behaviours
8️⃣ Risk & Impact Assessment
9️⃣ Recommended Actions & Communication Strategy
🔟 Behaviour Mitigation / Influence Strategies
1️⃣1️⃣ Urgency Flag
1️⃣2️⃣ Best Practices / References
Respond in a professional but beginner-friendly tone, using bullet points where helpful.
Input from user:
{user_input}
"""
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}
payload = {
"model": "openai/gpt-oss-20B", # updated model
"messages": [{"role": "user", "content": prompt}],
"temperature": 0.3
}
response = requests.post(
"https://api.groq.com/openai/v1/chat/completions",
headers=headers,
json=payload
)
if response.status_code == 200:
result = response.json()["choices"][0]["message"]["content"]
st.markdown("### 📝 Analysis Result")
st.write(result)
else:
st.error(f"API Error: {response.text}")