File size: 4,256 Bytes
9fd6a30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e7549fd
9fd6a30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
from pyexpat import model
from transformers import GPT2LMHeadModel, GPT2Tokenizer
from streamlit_lottie import st_lottie
import json
import pandas as pd
import requests
import torch
import tensorflow as tf
import streamlit as st
from streamlit_option_menu import option_menu

logo = "https://www.google.com/url?sa=i&url=https%3A%2F%2Ffr.depositphotos.com%2Fvector-images%2Frobot-logo.html&psig=AOvVaw14rAtmwJQVSpRFXFY6us7z&ust=1647274982461000&source=images&cd=vfe&ved=0CAsQjRxqFwoTCPjhzdO_w_YCFQAAAAAdAAAAABAD"
st.set_page_config(page_icon = logo, page_title ="Bonsoir !", layout = "wide")

@st.cache(allow_output_mutation=True)
def load_tokenizer():
        tokenizer = GPT2Tokenizer.from_pretrained("gpt2-large")
        model = GPT2LMHeadModel.from_pretrained("gpt2-large", pad_token_id=tokenizer.eos_token_id)
        return tokenizer

@st.cache(allow_output_mutation=True)
def load_model():
        model = GPT2LMHeadModel.from_pretrained("gpt2-large", pad_token_id=tokenizer.eos_token_id)
        return  model

tokenizer =load_tokenizer()
model = load_model()

def reponse(question, temp=0.5, long=40):
    
    input_ids = tokenizer.encode(question, return_tensors='pt')
    output = model.generate(input_ids, max_length=long, temperature =temp, num_beams=5, no_repeat_ngram_size=2, early_stopping=True)
    rep = tokenizer.decode(output[0], skip_special_tokens=True)
    return rep

def load_animation(url: str):
    r = requests.get(url)
    if r.status_code != 200 :
        return None
    return r.json()

url = "https://assets10.lottiefiles.com/packages/lf20_96bovdur.json"
robot = load_animation(url)


def contact_message():
    st.header(":mailbox: Let's Get In Touch !")

    name, message = st.columns((1,2))
    with name:
        contact_form = """<form action="https://formsubmit.co/maxime.letutour@gmail.com" method="POST">

     <input type="text" name="name" placeholder = "Ton Nom" required>

     <input type="email" name="email" placeholder = "Ton E-mail" required>

     </form>"""
        st.markdown(contact_form, unsafe_allow_html=True)

    with message :
        contact_form2 = """<form action="https://formsubmit.co/maxime.letutour@gmail.com" method="POST">

        <textarea name="message" placeholder="Ecris moi !"></textarea>

        <button type="submit">Send</button>

    """
        st.markdown(contact_form2, unsafe_allow_html=True)

    with open("style2.txt") as f:
        st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)



def robot():
    robot = load_animation(url)
    col1, col2, col3 = st.columns((5,1,5))

    with col1:

        st.subheader("Choose the length of my answer")
        long = st.number_input("Be aware that long answers require more time to think !", min_value=10, max_value=250, step =10)

        st.subheader("Ask me something")
        question = st.text_input('Be aware that I speak only english for the moment !',max_chars = 60)
        question = str(question)

        ok = st.button('Ask me')
        

    with col3:
        st_lottie(robot, speed=1, loop=True, quality = "low",height =300, width = 300)
        if ok:
            rep = reponse(question, long = long)
            

            rep_style = f'<p style="font-family:Lucida Handwriting; color:#00008B; font-size: 20px;">{rep}</p>'
            st.markdown(rep_style, unsafe_allow_html=True)
            




def main():
    st.title("Shall we chat ? Ask me a question")

    with st.sidebar:

        choice = option_menu(
            menu_title = "Ask Me",
            options = ["Question", "Envoie Moi Un Message"],
            icons=["chat","envelope"],
            menu_icon="robot"
        )

    if choice == "Envoie Moi Un Message":
        contact_message()
    
    elif choice == "Question":
        robot()

    st.sidebar.subheader(":notebook_with_decorative_cover: Par Maxime Le Tutour")

    st.sidebar.write(" :blue_book: [**Mon LinkedIn**](https://www.linkedin.com/in/maxime-le-tutour-95994795/)", unsafe_allow_html =True)

    
    




        


       
            



print("ok")














if __name__ == '__main__':
	main()