AmrithTech2K6/CSCLM
0
1import streamlit as st2import openai3import os4import random5 6# --- Configuration ---7API_KEY = os.environ.get("CSCLM2K6", "")8API_BASE_URL = os.environ.get("API_BASE_URL", "https://openrouter.ai/api/v1")9MODEL_NAME = os.environ.get("LLM_MODEL", "qwen/qwen-2.5-72b-instruct")10 11# --- Embedded Cloud Computing Topics (Ref 1) ---12TOPICS = [13 "Evolution from centralized to distributed systems: A technical timeline",14 "Client-server vs. peer-to-peer architecture: A comparative study",15 "Clustered computing: Types (high availability, load balancing, HPC)",16 "Grid computing fundamentals and its differences from cloud",17 "Utility computing: Pay-per-use model origins",18 "Virtualization as the core enabler of network-based systems",19 "Service-oriented architecture (SOA) in cloud environments",20 "Web services (REST, SOAP, WSDL, UDDI) for cloud interoperability",21 "Containerization (Docker) vs. virtual machines: Performance trade-offs",22 "Microservices architecture: Decomposing monolithic apps",23 "Serverless computing (FaaS): Event-driven network-based systems",24 "Software-defined networking (SDN) for cloud data centers",25 "Network function virtualization (NFV) in telecom clouds",26 "Message queuing systems (RabbitMQ, Kafka) for distributed communication",27 "Remote procedure calls (RPC/gRPC) in cloud-native apps",28 "Representational state transfer (REST) constraints for scalable APIs",29 "Edge computing: Extending network-based systems to the periphery",30 "Fog computing: Middle layer between edge and cloud",31 "Content delivery networks (CDN) as a distributed system",32 "Blockchain as a distributed ledger technology in cloud",33 "Distributed databases (Cassandra, CockroachDB) fundamentals",34 "In-memory data grids (Redis, Hazelcast) for performance",35 "Distributed file systems (Ceph, GlusterFS) basics",36 "Consensus algorithms (Paxos, Raft) in cloud systems",37 "Leader election and distributed coordination (ZooKeeper)",38 "Distributed transactions: Two-phase commit (2PC) vs. Saga pattern",39 "CAP theorem and its implications for cloud design",40 "Fallacies of distributed computing (L. Peter Deutsch)",41 "Case study: Google's Borg and Omega schedulers",42 "Case study: Amazon DynamoDB's distributed architecture",43 "Physical models vs. architectural models vs. formal models",44 "Synchronous vs. asynchronous distributed systems",45 "Failure models: Crash, omission, arbitrary (Byzantine) failures",46 "Security models: Threats, vulnerabilities, and trust models",47 "Scalability models: Vertical vs. horizontal scaling",48 "Load balancing models: Static, dynamic, and adaptive algorithms",49 "Workload models: CPU-bound, I/O-bound, memory-bound",50 "Data placement models in distributed storage",51 "Replication models: Active vs. passive replication",52 "Consistency models: Strong, eventual, causal, monotonic reads",53 "Client-server model: Strengths and limitations",54 "Peer-to-peer model: Structured (DHT) vs. unstructured",55 "Agent-based system models for autonomous cloud management",56 "Mobile code models: Code-on-demand, remote evaluation",57 "Cloud bursting model: Hybrid cloud scaling",58 "Multi-tenancy model: Isolation and resource sharing",59 "Publish-subscribe model for event-driven clouds",60 "Master-slave (master-worker) model for parallel processing",61 "Leader-follower replication model in databases",62 "Sharded (partitioned) system model for horizontal scaling",63 "Actor model for concurrent cloud computations (Akka, Orleans)",64 "Lambda architecture for big data (batch + speed layers)",65 "Kappa architecture: Stream-processing only",66 "Control plane vs. data plane separation model",67 "Stateful vs. stateless system models in cloud",68 "Model checking for distributed system verification",69 "Formal specification languages (TLA+, Alloy) for cloud designs",70 "Simulation tools (CloudSim, iFogSim) for modeling",71 "Performance modeling: Queuing theory for cloud centers",72 "Case study: System model of Kubernetes control plane"73]74 75# --- CSS Styling (Exact Requirements) ---76CUSTOM_CSS = """77<style>78/* Input & Result Fields: Blue background, white text, bold, slightly bigger, bold border */79.stTextInput input, .stTextArea textarea, 80div[data-testid="stTextInput"] input, div[data-testid="stTextArea"] textarea {81 background-color: #1E90FF !important;82 color: white !important;83 font-weight: bold !important;84 font-size: 17px !important;85 border: 3px solid #000080 !important;86}87 88/* Suggestion Prompts: Royal blue, bold, slightly bigger */89.suggestion-prompt {90 color: #4169E1 !important;91 font-weight: bold !important;92 font-size: 16px !important;93 padding: 6px 0;94 border-bottom: 1px dashed #4169E1;95 margin-bottom: 4px;96}97 98/* Button Styling */99.stButton > button {100 background-color: #1E90FF !important;101 color: white !important;102 font-weight: bold !important;103 font-size: 16px !important;104 border: 2px solid #000080 !important;105}106.stButton > button:hover {107 background-color: #104E8B !important;108}109 110/* Title & Subtitle Styling */111.main-title {112 text-align: center;113 font-size: 28px !important;114 font-weight: bold !important;115 margin-bottom: 10px;116}117.audience-tag {118 text-align: center;119 color: #555;120 font-size: 14px;121 margin-bottom: 20px;122}123</style>124"""125 126st.set_page_config(page_title="Cloud Computing Chatbot", layout="wide")127st.markdown(CUSTOM_CSS, unsafe_allow_html=True)128 129# --- Session State Management ---130if "result_text" not in st.session_state:131 st.session_state.result_text = ""132if "current_query" not in st.session_state:133 st.session_state.current_query = ""134if "suggestions" not in st.session_state:135 st.session_state.suggestions = random.sample(TOPICS, 10)136 137# --- UI Layout ---138st.markdown('<p class="main-title">⚖️ CLOUD COMPUTING for B.E.Computer Science/B.Tech Information Technology Chatbot</p>', unsafe_allow_html=True)139st.markdown('<p class="audience-tag">🎯 Target: B.E. CS Students | B.Tech IT Students | IT Job Seekers</p>', unsafe_allow_html=True)140 141# 1. System Suggestion Prompts (10 Random)142st.subheader("📌 System Suggestion Prompts")143cols = st.columns(2)144for i, topic in enumerate(st.session_state.suggestions):145 col_idx = i % 2146 with cols[col_idx]:147 st.markdown(f'<div class="suggestion-prompt">💡 {topic}</div>', unsafe_allow_html=True)148 if st.button(f"Load Prompt", key=f"load_{i}", use_container_width=True):149 st.session_state.current_query = topic150 st.session_state.result_text = ""151 st.rerun()152 153# 2. Text Field 1: User Query154st.subheader("🔍 Query Input")155user_query = st.text_input(156 "Enter your Cloud Computing query:",157 value=st.session_state.current_query,158 key="main_input"159)160 161# Submit Button162submit_pressed = st.button("Submit Prompt", use_container_width=True)163 164# 3. Text Field 2: Multi-line Result165st.subheader("📤 Result Set")166result_area = st.text_area(167 "Retrieved Response:",168 value=st.session_state.result_text,169 height=250,170 key="result_area",171 disabled=True172)173 174# 4. Reset Button175if st.button("🔄 Reset", use_container_width=True):176 st.session_state.result_text = ""177 st.session_state.current_query = ""178 st.session_state.suggestions = random.sample(TOPICS, 10)179 st.rerun()180 181# --- Backend Logic ---182if submit_pressed and user_query:183 if not API_KEY or API_KEY == "":184 st.session_state.result_text = "⚠️ API Key missing. Please set 'CSCLM2K6' in Hugging Face Space Secrets."185 st.rerun()186 else:187 with st.spinner("🤖 Processing via Qwen AI..."):188 try:189 client = openai.OpenAI(api_key=API_KEY, base_url=API_BASE_URL)190 system_prompt = (191 "You are an expert Cloud Computing tutor for B.E. Computer Science and B.Tech IT students, "192 "and a technical interviewer for IT job seekers. Base your answers strictly on the 60 core "193 "Cloud Computing topics provided in your training. Provide clear, structured, exam & interview-ready "194 "explanations. Keep responses concise and technically accurate."195 )196 response = client.chat.completions.create(197 model=MODEL_NAME,198 messages=[199 {"role": "system", "content": system_prompt},200 {"role": "user", "content": user_query}201 ],202 temperature=0.3,203 max_tokens=1200204 )205 st.session_state.result_text = response.choices[0].message.content206 except Exception as e:207 st.session_state.result_text = f"❌ API Error: {str(e)}\nVerify your API Key & Base URL in Space Secrets."208 st.rerun()