baptiste.bernard commited on
Commit
74b66c1
·
1 Parent(s): 8095b8a

Readme and add file to bot

Browse files
Files changed (3) hide show
  1. README.md +122 -1
  2. app.py +32 -35
  3. logo-gaia.png +0 -0
README.md CHANGED
@@ -10,4 +10,125 @@ pinned: false
10
  license: mit
11
  ---
12
 
13
- An example chatbot using [Gradio](https://gradio.app), [`huggingface_hub`](https://huggingface.co/docs/huggingface_hub/v0.22.2/en/index), and the [Hugging Face Inference API](https://huggingface.co/docs/api-inference/index).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  license: mit
11
  ---
12
 
13
+ ### Choisir la langue : [Français](#français) | [English](#english)
14
+
15
+ ## Français
16
+
17
+ <a name="français"></a>
18
+
19
+ ## Description
20
+
21
+ Gaia Chat est un exemple de chatbot utilisant [Gradio](https://gradio.app), [`huggingface_hub`](https://huggingface.co/docs/huggingface_hub/v0.22.2/en/index), et l'[API d'inférence de Hugging Face](https://huggingface.co/docs/api-inference/index). Ce projet montre comment créer un chatbot interactif en utilisant ces outils.
22
+
23
+ ## Prérequis
24
+
25
+ - Python 3.6 ou supérieur
26
+ - Gradio
27
+ - Chardet
28
+
29
+
30
+ ## Installation
31
+
32
+ ### 1. Installer Python
33
+
34
+ Assurez-vous que Python est installé.
35
+
36
+ ```sh
37
+ python --version
38
+ ```
39
+
40
+ 1. Rendez-vous sur le site officiel de Python : [https://www.python.org/downloads/](https://www.python.org/downloads/)
41
+ 2. Vérifiez l’installation avec la commande :
42
+ ```sh
43
+ python --version
44
+ ```
45
+
46
+
47
+
48
+ ### 2. Installer les dépendances
49
+
50
+ Installez `Gradio` :
51
+
52
+ ```sh
53
+ pip install gradio
54
+ ```
55
+
56
+ Installez `Chardet` :
57
+
58
+ ```sh
59
+ pip install chardet
60
+ ```
61
+ ### 5. Gener un Access token sur Hugging Face
62
+
63
+ Rendez-vous sur votre profil Hugging Face pour genenez votre Access Token : [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens)
64
+
65
+ ### 4. Lancer l'application
66
+
67
+ Exécutez la commande suivante pour démarrer Gaia Chat :
68
+
69
+ ```sh
70
+ python app.py
71
+ ```
72
+
73
+ Une fois l'application lancée, ouvrez votre navigateur et accédez à l'URL indiquée dans le terminal pour interagir avec le chatbot.
74
+
75
+
76
+ ---
77
+
78
+
79
+ ## English
80
+
81
+ <a name="english"></a>
82
+
83
+
84
+ ## Description
85
+
86
+ Gaia Chat is an example chatbot using [Gradio](https://gradio.app), [`huggingface_hub`](https://huggingface.co/docs/huggingface_hub/v0.22.2/en/index), and l '[Hugging Face Inference API](https://huggingface.co/docs/api-inference/index). This project shows how to create an interactive chatbot using these tools.
87
+
88
+
89
+ ## prerequisites
90
+
91
+ - Python 3.6
92
+ - Gradio
93
+ - Chardet
94
+
95
+ ## Facilities
96
+
97
+ ### 1. Python install
98
+
99
+ Make sure Python is installed.
100
+
101
+ ```sh
102
+ python --version
103
+ ```
104
+
105
+ 1. Go to the official Python website: [https://www.python.org/downloads/](https://www.python.org/downloads/)
106
+ 2. Verify the installation with the command:
107
+ ```sh
108
+ python --version
109
+ ```
110
+
111
+ ### 2. Install dependencies
112
+
113
+ Install `Gradio` :
114
+ ```sh
115
+ pip install gradio
116
+ ```
117
+
118
+ Install `Chardet`
119
+ ```sh
120
+ pip install chardet
121
+ ```
122
+ ### 5. Generate Access Token on Hugging Face
123
+
124
+ Go to your Hugging Face profile to generate your access token: [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens)
125
+
126
+ ### 4. Launch the application
127
+
128
+ Run the following command to start Gaia Chat:
129
+
130
+ ```sh
131
+ python app.py
132
+ ```
133
+
134
+ Once the application is launched, open your browser and navigate to the URL given in the terminal to interact with the chatbot.
app.py CHANGED
@@ -1,32 +1,38 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
 
3
 
4
- """
5
- For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
- """
7
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
 
 
9
 
10
- def respond(
11
- message,
12
- history: list[tuple[str, str]],
13
- system_message,
14
- max_tokens,
15
- temperature,
16
- top_p,
17
- ):
18
- messages = [{"role": "system", "content": system_message}]
19
 
 
20
  for val in history:
21
  if val[0]:
22
  messages.append({"role": "user", "content": val[0]})
23
  if val[1]:
24
  messages.append({"role": "assistant", "content": val[1]})
25
-
26
  messages.append({"role": "user", "content": message})
27
 
28
  response = ""
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  for message in client.chat_completion(
31
  messages,
32
  max_tokens=max_tokens,
@@ -35,30 +41,21 @@ def respond(
35
  top_p=top_p,
36
  ):
37
  token = message.choices[0].delta.content
38
-
39
  response += token
40
  yield response
41
 
42
-
43
- """
44
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
45
- """
46
- demo = gr.ChatInterface(
47
- respond,
48
- additional_inputs=[
49
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
50
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
51
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
52
- gr.Slider(
53
- minimum=0.1,
54
- maximum=1.0,
55
- value=0.95,
56
- step=0.05,
57
- label="Top-p (nucleus sampling)",
58
- ),
59
- ],
60
- )
61
-
62
 
63
  if __name__ == "__main__":
64
  demo.launch()
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
+ import chardet
4
 
5
+ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta", token="") #generate Access tokens
 
 
 
6
 
7
+ file_content = None
8
 
9
+ def respond(message, history, system_message, max_tokens, temperature, top_p, file=None):
10
+ global file_content
 
 
 
 
 
 
 
11
 
12
+ messages = [{"role": "system", "content": system_message}]
13
  for val in history:
14
  if val[0]:
15
  messages.append({"role": "user", "content": val[0]})
16
  if val[1]:
17
  messages.append({"role": "assistant", "content": val[1]})
18
+
19
  messages.append({"role": "user", "content": message})
20
 
21
  response = ""
22
 
23
+ if file:
24
+ try:
25
+ file_content = file.decode("utf-8")
26
+ except UnicodeDecodeError:
27
+ result = chardet.detect(file)
28
+ encoding = result['encoding']
29
+ file_content = file.decode(encoding, errors='ignore')
30
+
31
+ if "contenu du fichier" in message.lower() and file_content:
32
+ response += f"Contenu du fichier :\n{file_content}"
33
+ yield response
34
+ return
35
+
36
  for message in client.chat_completion(
37
  messages,
38
  max_tokens=max_tokens,
 
41
  top_p=top_p,
42
  ):
43
  token = message.choices[0].delta.content
 
44
  response += token
45
  yield response
46
 
47
+ with gr.Blocks() as demo:
48
+ gr.Image(value="logo-gaia.png", label="Logo")
49
+ gr.ChatInterface(
50
+ respond,
51
+ additional_inputs=[
52
+ gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
53
+ gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
54
+ gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
55
+ gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
56
+ gr.File(label="Télécharger un fichier", type="binary"),
57
+ ],
58
+ )
 
 
 
 
 
 
 
 
59
 
60
  if __name__ == "__main__":
61
  demo.launch()
logo-gaia.png ADDED