Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""
|
3 |
+
Created on Tue Oct 22 08:19:29 2024
|
4 |
+
|
5 |
+
@author: kadenyo
|
6 |
+
"""
|
7 |
+
|
8 |
+
# chatbot.py
|
9 |
+
# Import necessary modules
|
10 |
+
from langchain_core.prompts import ChatPromptTemplate
|
11 |
+
from langchain_community.llms import Ollama
|
12 |
+
import streamlit as st
|
13 |
+
|
14 |
+
# Define a prompt template for the chatbot
|
15 |
+
prompt=ChatPromptTemplate.from_messages(
|
16 |
+
[
|
17 |
+
("system","You are a helpful assistant. Please response to the questions"),
|
18 |
+
("user","Question:{question}")
|
19 |
+
]
|
20 |
+
)
|
21 |
+
|
22 |
+
# Set up the Streamlit framework
|
23 |
+
st.title('Langchain Chatbot With LLAMA2 model') # Set the title of the Streamlit app
|
24 |
+
input_text=st.text_input("Ask your question!") # Create a text input field in the Streamlit app
|
25 |
+
|
26 |
+
# Initialize the Ollama model
|
27 |
+
llm=Ollama(model="llama2")
|
28 |
+
|
29 |
+
# Create a chain that combines the prompt and the Ollama model
|
30 |
+
chain=prompt|llm
|
31 |
+
|
32 |
+
# Invoke the chain with the input text and display the output
|
33 |
+
if input_text:
|
34 |
+
st.write(chain.invoke({"question":input_text}))
|