File size: 2,759 Bytes
ed54ae1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34cb55c
ed54ae1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86e1bd6
ed54ae1
 
 
 
 
 
 
 
 
2a20ce6
 
ed54ae1
 
d81debe
ed54ae1
 
d81debe
ed54ae1
 
 
 
c40a97c
81e1697
 
2a20ce6
81e1697
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2a20ce6
81e1697
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from langchain_community.chat_message_histories import StreamlitChatMessageHistory
import streamlit as st
from langchain.prompts import (
    ChatPromptTemplate,
    HumanMessagePromptTemplate,
    MessagesPlaceholder,
)
from more_itertools import chunked

from langserve import RemoteRunnable
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import os
from langchain import PromptTemplate
from langchain import LLMChain
from langchain_together import Together
import re
import pdfplumber
# Set the API key with double quotes

os.environ['TOGETHER_API_KEY'] = "5653bbfbaf1f7c1438206f18e5dfc2f5992b8f0b6aa9796b0131ea454648ccde"

text = ""
max_pages = 16
with pdfplumber.open("AI Engineer Test.pdf") as pdf:
        for i, page in enumerate(pdf.pages):
            if i >= max_pages:
                break
            text += page.extract_text() + "\n"

def Bot(Questions):
    chat_template = """
    Based on the provided context: {text}
    Please answer the following question: {Questions}
    Only provide answers that are directly related to the context. If the question is unrelated, respond with "I don't know".
    """
    prompt = PromptTemplate(
        input_variables=['text', 'Questions'],
        template=chat_template
    )
    llama3 = Together(model="meta-llama/Llama-3-70b-chat-hf", max_tokens=250)
    Generated_chat = LLMChain(llm=llama3, prompt=prompt)

   
def ChatBot(Questions):
  greetings = ["hi", "hello", "hey", "greetings", "what's up", "howdy"]
    # Check if the input question is a greeting
  question_lower = Questions.lower().strip()
  if question_lower in greetings or any(question_lower.startswith(greeting) for greeting in greetings):
        return "Hello! How can I assist you with the document today?"
  else:
    response=Bot(Questions)
    return response.translate(str.maketrans('', '', '\n'))
"""
  # --- Logo ---
st.set_page_config(
    page_title="AI Engineer Test Chatbot",
    page_icon="Insight Therapy Solutions.png",
    layout="wide",
)
st.sidebar.image("Insight Therapy Solutions.png", width=200)

st.sidebar.title("Navigation")
st.sidebar.write("Reclaim Your Mental Health")
st.sidebar.markdown("[Visit us at](https://www.insighttherapysolutions.com/)")
"""
# Add some custom styling
st.markdown(
    
    <style>
    .css-18e3th9 {
        padding-top: 3rem;
    }
    .css-1d391kg {
        text-align: center;
    }
    .stButton>button {
        background-color: #4CAF50;
        color: white;
        border: none;
        padding: 15px 32px;
        text-align: center;
        text-decoration: none;
        display: inline-block;
        font-size: 16px;
        margin: 4px 2px;
        cursor: pointer;
        border-radius: 8px;
    }
    </style>
    , unsafe_allow_html=True
)