File size: 1,130 Bytes
f136beb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a2e742e
f136beb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from transformers import pipeline
import pandas as pd

qa_pipeline = pipeline("question-answering", model='deepset/roberta-base-squad2')

def chatbot(question):
    with open(r"ayurdata.txt", "r", encoding="utf-8") as file:
        context = file.read()
    answer = qa_pipeline(question=question, context=context)
    return answer

def prints(questions):
    response = chatbot(questions)
    return response['answer']

import streamlit as st
st.title("Ford AI Bot")
if "messages" not in st.session_state:
    st.session_state.messages = []
    st.session_state.messages.append({
        'role':'assistant',
        'content':"Hi! I'm your AI Bot"
    })
for message in st.session_state.messages:
  with st.chat_message(message["role"]):
    st.markdown(message["content"])
prompt = st.chat_input("What is up?")
if prompt:
  with st.chat_message("user"):
    st.markdown(prompt)
  st.session_state.messages.append({"role":"user","content":prompt})
  response = f"ChatBot: {prints(prompt)}"
  with st.chat_message("assistant"):
    st.markdown(response)
  st.session_state.messages.append({"role":"assistant","content":response})