LexGuardian / app.py
sunbal7's picture
Update app.py
35fc402 verified
raw
history blame
1.7 kB
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.`")