Rohankumar31 commited on
Commit
a696e53
1 Parent(s): e0c3467

Upload 2 files

Browse files
Files changed (2) hide show
  1. main.py +10 -0
  2. stream.py +22 -0
main.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import transformers
2
+ from transformers import TFGPT2LMHeadModel ,GPT2Tokenizer, BitsAndBytesConfig
3
+ import tensorflow as tf
4
+ tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
5
+ model = TFGPT2LMHeadModel.from_pretrained('gpt2',pad_token_id = tokenizer.eos_token_id)
6
+ def generate_text(inp):
7
+ input_ids = tokenizer.encode(inp,return_tensors = 'tf')
8
+ beam_output = model.generate(input_ids, max_length = 100,num_beams = 5, no_repeat_ngram_size = 2, early_stopping = True)
9
+ output = tokenizer.decode(beam_output[0],skip_special_tokens = True, clean_up_tokenization_spaces = True)
10
+ return ".".join(output.split(".")[:-1]) + "."
stream.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from main import generate_text
3
+ st.title("Health Suggestion Bot - Prakruti 🍃")
4
+ st.write("Prakruti, in Ayurveda, refers to an individual's unique physical and psychological constitution. It is determined by the balance of three fundamental energies or doshas: Vata, Pitta, and Kapha. Understanding one's Prakruti helps tailor health and lifestyle choices for overall well-being.")
5
+ if "messages" not in st.session_state:
6
+ st.session_state.messages = []
7
+ st.session_state.messages.append({
8
+ 'role':'assistant',
9
+ 'content':"Hi! I'm your virtual assistant you can ask any query to me"
10
+ })
11
+ for message in st.session_state.messages:
12
+ with st.chat_message(message["role"]):
13
+ st.markdown(message["content"])
14
+ prompt = st.chat_input("What is up?")
15
+ if prompt:
16
+ with st.chat_message("user"):
17
+ st.markdown(prompt)
18
+ st.session_state.messages.append({"role":"user","content":prompt})
19
+ response = f"ChatBot: {generate_text(prompt)}"
20
+ with st.chat_message("assistant"):
21
+ st.markdown(response)
22
+ st.session_state.messages.append({"role":"assistant","content":response})