Spaces:
Runtime error
Runtime error
Rohankumar31
commited on
Commit
•
ae21aa7
1
Parent(s):
5921691
Upload 2 files
Browse files
main.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import transformers
|
2 |
+
import torch
|
3 |
+
import torch.nn as nn
|
4 |
+
import tensorflow as tf
|
5 |
+
from transformers import TFGPT2LMHeadModel ,GPT2Tokenizer, BitsAndBytesConfig
|
6 |
+
tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
|
7 |
+
model = TFGPT2LMHeadModel.from_pretrained('gpt2',pad_token_id = tokenizer.eos_token_id)
|
8 |
+
def generate_text(inp):
|
9 |
+
input_ids = tokenizer.encode(inp,return_tensors = 'tf')
|
10 |
+
beam_output = model.generate(input_ids, max_length = 100,num_beams = 5, no_repeat_ngram_size = 2, early_stopping = True)
|
11 |
+
output = tokenizer.decode(beam_output[0],skip_special_tokens = True, clean_up_tokenization_spaces = True)
|
12 |
+
return ".".join(output.split(".")[:-1]) + "."
|
stream.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from main import generate_text
|
3 |
+
st.title("AI Chaperone 🎗️")
|
4 |
+
st.write("AI Chaperone is an advanced AI assistant meticulously designed to provide unwavering support to individuals living with Alzheimer's disease.")
|
5 |
+
if "messages" not in st.session_state:
|
6 |
+
st.session_state.messages = []
|
7 |
+
for message in st.session_state.messages:
|
8 |
+
with st.chat_message(message["role"]):
|
9 |
+
st.markdown(message["content"])
|
10 |
+
prompt = st.chat_input("What is up?")
|
11 |
+
if prompt:
|
12 |
+
with st.chat_message("user"):
|
13 |
+
st.markdown(prompt)
|
14 |
+
st.session_state.messages.append({"role":"user","content":prompt})
|
15 |
+
response = f"ChatBot: {generate_text(prompt)}"
|
16 |
+
with st.chat_message("assistant"):
|
17 |
+
st.markdown(response)
|
18 |
+
st.session_state.messages.append({"role":"assistant","content":response})
|