Spaces:
Sleeping
Sleeping
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.`") | |