import streamlit as st import requests # Set your OpenRouter API key here API_KEY = "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" # ๐Ÿ” Replace with your key API_URL = "https://openrouter.ai/api/v1/chat/completions" HEADERS = { "Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json" } def query_llm(prompt): data = { "model": "mistralai/mistral-7b-instruct", "messages": [ {"role": "system", "content": "You are a helpful science teacher for school students."}, {"role": "user", "content": prompt} ] } try: response = requests.post(API_URL, headers=HEADERS, json=data) res = response.json() return res["choices"][0]["message"]["content"] except Exception as e: return f"โŒ Error: {str(e)}" # Streamlit UI st.set_page_config(page_title="Science Lab Assistant", page_icon="๐Ÿงช") st.title("๐Ÿงช Science Lab Assistant") st.subheader("Ask me about school science experiments!") with st.form("lab_form"): experiment = st.text_input("๐Ÿ” Enter your experiment name or question:") hypothesis = st.text_area("๐Ÿ’ก What is your hypothesis?") submitted = st.form_submit_button("Explain Experiment") if submitted and experiment: prompt = f"Explain the experiment '{experiment}' for a school science class. The student hypothesizes: '{hypothesis}'. Provide an explanation and expected results." result = query_llm(prompt) st.markdown("### ๐Ÿง  AI Explanation") st.write(result) st.markdown("---") st.markdown("๐Ÿ“š Example: `Vinegar and baking soda`") st.markdown("๐Ÿ’ก Hypothesis: `Combining them will create bubbles.`")