Spaces:
Sleeping
Sleeping
Update src/app.py
Browse files- src/app.py +29 -14
src/app.py
CHANGED
|
@@ -1,19 +1,34 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
st.set_page_config(page_title="Ollama
|
| 5 |
-
st.title("🧠 Chat with Ollama via Python Client")
|
| 6 |
|
| 7 |
-
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from langchain_community.llms import Ollama
|
| 3 |
+
from langchain.chains import LLMChain
|
| 4 |
+
from langchain.prompts import PromptTemplate
|
| 5 |
|
| 6 |
+
st.set_page_config(page_title="🧪 LangChain + Ollama Notebook")
|
|
|
|
| 7 |
|
| 8 |
+
st.title("📓 LangChain + Ollama Jupyter-like App")
|
| 9 |
|
| 10 |
+
# Setup LangChain LLM with Ollama backend
|
| 11 |
+
llm = Ollama(model="llama3", base_url="http://localhost:11434")
|
| 12 |
|
| 13 |
+
# Notebook-style prompt block
|
| 14 |
+
code_cell = st.text_area("🧠 Enter your notebook-style cell (text or code):", height=200)
|
| 15 |
+
run_button = st.button("▶️ Run")
|
| 16 |
+
|
| 17 |
+
# Prompt template with notebook context
|
| 18 |
+
template = """
|
| 19 |
+
You are a helpful AI assistant embedded in a Jupyter-style notebook.
|
| 20 |
+
Interpret the input below and respond helpfully.
|
| 21 |
+
|
| 22 |
+
Input:
|
| 23 |
+
{cell_input}
|
| 24 |
+
|
| 25 |
+
Response:"""
|
| 26 |
+
|
| 27 |
+
prompt = PromptTemplate(template=template, input_variables=["cell_input"])
|
| 28 |
+
chain = LLMChain(llm=llm, prompt=prompt)
|
| 29 |
+
|
| 30 |
+
if run_button and code_cell.strip():
|
| 31 |
+
with st.spinner("Running cell..."):
|
| 32 |
+
result = chain.run(cell_input=code_cell)
|
| 33 |
+
st.markdown("### 📬 Response")
|
| 34 |
+
st.write(result)
|