Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from langchain_openai import ChatOpenAI
|
2 |
+
from langchain_core.prompts import ChatPromptTemplate
|
3 |
+
from langchain_core.output_parsers import StrOutputParser
|
4 |
+
from langchain_community.llms import Ollama
|
5 |
+
import streamlit as st
|
6 |
+
import os
|
7 |
+
from dotenv import load_dotenv
|
8 |
+
|
9 |
+
# Load environment variables
|
10 |
+
load_dotenv()
|
11 |
+
|
12 |
+
os.environ["LANGCHAIN_TRACING_V2"] = "true"
|
13 |
+
os.environ["LANGCHAIN_API_KEY"] = os.getenv("LANGCHAIN_API_KEY")
|
14 |
+
|
15 |
+
# Prompt Template
|
16 |
+
prompt = ChatPromptTemplate.from_messages(
|
17 |
+
[
|
18 |
+
("system", "You are a helpful assistant. Please respond to the user queries"),
|
19 |
+
("user", "Question: {question}")
|
20 |
+
]
|
21 |
+
)
|
22 |
+
|
23 |
+
# Streamlit app
|
24 |
+
st.title('Langchain Demo With LLAMA2 API')
|
25 |
+
input_text = st.text_input("Search the topic you want")
|
26 |
+
|
27 |
+
# Ollama LLama2 LLM
|
28 |
+
llm = Ollama(model="llama2")
|
29 |
+
output_parser = StrOutputParser()
|
30 |
+
chain = prompt | llm | output_parser
|
31 |
+
|
32 |
+
# Display result when user inputs text
|
33 |
+
if input_text:
|
34 |
+
response = chain.invoke({"question": input_text})
|
35 |
+
st.write(response)
|