import streamlit as st import requests import os # Configuration API_URL = "https://openrouter.ai/api/v1/chat/completions" API_KEY = os.environ.get("SAPFICOKEY") MODEL_NAME = "qwen/qwen-2.5-72b-instruct" # Simple system prompt SYSTEM_PROMPT = """You are an expert SAP S/4HANA FICO consultant. Answer questions for students and professionals in Commerce, CS, MBA Finance, and SAP domains. Keep answers clear, structured, and professional.""" # Quick suggestions SUGGESTIONS = [ "What is SAP S/4HANA FICO?", "Explain Universal Journal (ACDOCA)", "Difference between FI and CO?", "S/4HANA migration paths?", "Career in SAP FICO?" ] # Page config st.set_page_config(page_title="SAP FICO Chatbot", page_icon="⚖️", layout="centered") # Title st.title("⚖️ SAP S/4HANA FICO Chatbot") st.markdown("**Powered by Qwen via OpenRouter**") # Sidebar with st.sidebar: st.header("Controls") if st.button("🔄 Reset", use_container_width=True): st.session_state.clear() st.rerun() st.info("Model: qwen-2.5-72b-instruct") # Quick suggestions st.markdown("### 💡 Quick Questions:") cols = st.columns(5) for i, prompt in enumerate(SUGGESTIONS): with cols[i]: if st.button(prompt, key=f"q{i}", use_container_width=True): st.session_state.quick_query = prompt # Input area st.markdown("### 📝 Your Question:") user_input = st.text_area( "Enter your SAP FICO query", value=st.session_state.get("quick_query", ""), height=100, placeholder="e.g., What is the Universal Journal?" ) # Submit button if st.button("🚀 Submit Query", type="primary", use_container_width=True): if not user_input: st.warning("Please enter a question") elif not API_KEY: st.error("API Key not configured!") else: with st.spinner("Getting answer..."): try: headers = { "Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json" } payload = { "model": MODEL_NAME, "messages": [ {"role": "system", "content": SYSTEM_PROMPT}, {"role": "user", "content": user_input} ], "max_tokens": 800 } response = requests.post(API_URL, headers=headers, json=payload, timeout=30) response.raise_for_status() answer = response.json()['choices'][0]['message']['content'] # Display result st.markdown("### ✅ Answer:") st.info(answer) except Exception as e: st.error(f"Error: {str(e)}") # Footer st.markdown("---") st.caption("SAP FICO Chatbot | MIT License")