Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
API_URL = "http://127.0.0.1:8000"
|
| 5 |
+
|
| 6 |
+
st.title("Mechanistic Analysis Interface")
|
| 7 |
+
st.write("Run GPT-2 generation + activation patching experiments.")
|
| 8 |
+
|
| 9 |
+
prompt = st.text_area("Enter your sentence:")
|
| 10 |
+
|
| 11 |
+
if st.button("Run Experiment"):
|
| 12 |
+
if prompt:
|
| 13 |
+
with st.spinner("Running experiment..."):
|
| 14 |
+
response = requests.post(f"{API_URL}/generate", json={"prompt": prompt})
|
| 15 |
+
data = response.json()
|
| 16 |
+
|
| 17 |
+
st.subheader("Generated Text")
|
| 18 |
+
st.write(data["generated_text"])
|
| 19 |
+
|
| 20 |
+
st.subheader("Activation Patching Traces")
|
| 21 |
+
st.write(data["activations"])
|
| 22 |
+
|
| 23 |
+
st.subheader("Explanation")
|
| 24 |
+
st.write(data["explanation"])
|
| 25 |
+
|
| 26 |
+
st.success(f"Experiment saved with ID: {data['id']}")
|