FFatih commited on
Commit
7474d35
·
0 Parent(s):

Synchronisation Production

Browse files
Files changed (4) hide show
  1. README.md +37 -0
  2. app.py +7 -0
  3. gradio.py +100 -0
  4. requirements.txt +3 -0
README.md ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: SAE-GPT2
3
+ emoji: ❤️
4
+ colorFrom: indigo
5
+ colorTo: red
6
+ sdk: gradio
7
+ sdk_version: 3.50.2
8
+ app_file: app.py
9
+ pinned: false
10
+ ---
11
+
12
+ <hr/>
13
+
14
+ <h4> Environnement de développement commun </h4>
15
+
16
+ <br/>
17
+
18
+ | Nom | Lien |
19
+ |------------|-------------------------------------------------------|
20
+ | Production | https://huggingface.co/spaces/FFatih/SAE-GPT2-PROD |
21
+ | Recette | https://huggingface.co/spaces/FFatih/SAE-GPT2-RECETTE |
22
+
23
+ <hr/>
24
+
25
+ <h4> Environnement de développement personnel </h4>
26
+
27
+ <br/>
28
+
29
+ | Prenom | Lien |
30
+ |-------------------|------------------------------------------------------------|
31
+ | Fatih | https://huggingface.co/spaces/FFatih/SAE-GPT2-FATIH |
32
+ | Bastien | https://huggingface.co/spaces/BastienHot/SAE-GPT2-BASTIEN |
33
+ | Pascal | https://huggingface.co/spaces/PascalZhan/SAE-GPT2-PASCAL |
34
+ | Tamij | https://huggingface.co/spaces/Tamij/SAE-GPT2-TAMIJ |
35
+ | Kevin | https://huggingface.co/spaces/Kemasu/SAE-GPT2-KEVIN |
36
+ | Lilian | https://huggingface.co/spaces/Solialiranes/SAE-GPT2-LILIAN |
37
+ | Evan | https://huggingface.co/spaces/Evanparis240/SAE-GPT2-EVAN |
app.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ def greet(name):
4
+ return "Hello " + name + "!!"
5
+
6
+ iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
+ iface.launch()
gradio.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """Untitled3.ipynb
3
+
4
+ Automatically generated by Colaboratory.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1zwLQmMKCQKLMkJ_5Un4C6V4ajs4LYUOR
8
+ """
9
+ """
10
+ !pip install --upgrade typing-extensions -q
11
+ !pip install -q gradio --upgrade -q
12
+ !pip install keras_nlp -q
13
+ """
14
+ from google.colab import drive
15
+ drive.mount('/content/drive')
16
+
17
+ import os
18
+ from tensorflow import keras
19
+ import keras_nlp
20
+ import gradio as gr
21
+ import random
22
+ import time
23
+
24
+ os.environ["KERAS_BACKEND"] = "tensorflow" # or "tensorflow" or "torch"
25
+ keras.mixed_precision.set_global_policy("mixed_float16")
26
+
27
+ preprocessor = keras_nlp.models.GPT2CausalLMPreprocessor.from_preset(
28
+ "gpt2_large_en",
29
+ sequence_length=256,
30
+ )
31
+ gpt2_lm = keras_nlp.models.GPT2CausalLM.from_preset(
32
+ "gpt2_large_en", preprocessor=preprocessor
33
+ )
34
+
35
+ gpt2_lm.load_weights('./drive/MyDrive/checkpoints/my_checkpoint')
36
+
37
+ css = """
38
+ .gradio-container {
39
+ background-color: transparent;
40
+ color: #f5f5dc;
41
+ border-color: #d5aa5e;
42
+ }
43
+ /* Styling for the chatbot */
44
+ .chat{
45
+ border-color: #d5aa5e;
46
+ background-color:#22201f;
47
+ background-image: url('https://github.com/BastienHot/SAE-GPT2/blob/70fb88500a2cc168d71e8ed635fc54492beb6241/image/logo.png');
48
+ background-size: cover;
49
+ background-position: center;
50
+ }
51
+
52
+ /* Styling for the user */
53
+ .user{
54
+ background-color: #957d52;
55
+ }
56
+
57
+ /* Styling for the text inside the chatbot */
58
+ .gradio-chatbox .message-container .message-right {
59
+ color: #f5f5dc; /* Antique white text color */
60
+ border-color: #d5aa5e;
61
+ background-color: red;
62
+ }
63
+
64
+ .md svelte-1syupzx chatbot{
65
+ border-color: #d5aa5e;
66
+ background-color: #3e3836;
67
+ }
68
+
69
+ .message user svelte-1lcyrx4 message-bubble-border {
70
+ border-color: #3e3836;
71
+ }
72
+
73
+
74
+ """
75
+
76
+ def predict(text):
77
+ # Simulating model prediction
78
+ return gpt2_lm.generate(text)
79
+
80
+ with gr.Blocks(css=css) as demo:
81
+ chatbot = gr.Chatbot(elem_classes="chat")
82
+ msg = gr.Textbox(elem_classes="user")
83
+ clear = gr.ClearButton([msg, chatbot])
84
+
85
+ def respond(message, chat_history):
86
+ bot_message = predict(message)
87
+ # Ajouter une classe pour la partie bot_message
88
+ bot_message_html = f'<div class="bot-message">{bot_message}</div>'
89
+ # Ajouter une classe pour la partie message
90
+ user_message_html = f'<div class="user-message">{message}</div>'
91
+ chat_history.append((user_message_html, bot_message_html))
92
+ time.sleep(2)
93
+ return "", chat_history
94
+
95
+ msg.submit(respond, [msg, chatbot], [msg, chatbot])
96
+
97
+
98
+ if __name__ == "__main__":
99
+ demo.launch(debug=True, share=True)
100
+
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ keras_nlp
3
+ typing-extensions