Martial667 commited on
Commit
a9c74c7
·
verified ·
1 Parent(s): 73ddaec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -21
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
-
5
  def respond(
6
  message,
7
  history: list[dict[str, str]],
@@ -12,14 +11,13 @@ def respond(
12
  hf_token: gr.OAuthToken,
13
  ):
14
  """
15
- 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
16
  """
 
17
  client = InferenceClient(token=hf_token.token, model="deepseek-ai/DeepSeek-V3.2")
18
 
19
  messages = [{"role": "system", "content": system_message}]
20
-
21
  messages.extend(history)
22
-
23
  messages.append({"role": "user", "content": message})
24
 
25
  response = ""
@@ -40,32 +38,72 @@ def respond(
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
- chatbot = gr.ChatInterface(
47
  respond,
48
  type="messages",
 
 
 
 
 
 
 
 
 
 
49
  additional_inputs=[
50
- gr.Markdown("#Le chatbot qu'il vous faut"),
51
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
52
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
53
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
54
- gr.Slider(
55
- minimum=0.1,
56
- maximum=1.0,
57
- value=0.95,
58
- step=0.05,
59
- label="Top-p (nucleus sampling)",
60
- ),
61
  ],
 
 
 
 
 
 
 
 
62
  )
63
 
64
- with gr.Blocks() as demo:
65
  with gr.Sidebar():
66
- gr.LoginButton()
67
- chatbot.render()
68
-
 
 
69
 
70
  if __name__ == "__main__":
71
- demo.launch(share=True)
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
 
4
  def respond(
5
  message,
6
  history: list[dict[str, str]],
 
11
  hf_token: gr.OAuthToken,
12
  ):
13
  """
14
+ Logique de réponse utilisant l'API Inference.
15
  """
16
+
17
  client = InferenceClient(token=hf_token.token, model="deepseek-ai/DeepSeek-V3.2")
18
 
19
  messages = [{"role": "system", "content": system_message}]
 
20
  messages.extend(history)
 
21
  messages.append({"role": "user", "content": message})
22
 
23
  response = ""
 
38
  yield response
39
 
40
 
41
+
42
+ custom_theme = gr.themes.Soft(
43
+ primary_hue="indigo",
44
+ secondary_hue="violet",
45
+ neutral_hue="slate",
46
+ font=[gr.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui"],
47
+ ).set(
48
+ body_background_fill="*neutral_50",
49
+ block_background_fill="white",
50
+ block_shadow="*shadow_drop_lg",
51
+ button_primary_background_fill="*primary_500",
52
+ button_primary_text_color="white",
53
+ )
54
+
55
+ custom_css = """
56
+ h1 {
57
+ text-align: center;
58
+ color: #4f46e5;
59
+ font-weight: 800 !important;
60
+ font-size: 2.5rem !important;
61
+ margin-bottom: 10px;
62
+ }
63
+ .description {
64
+ text-align: center;
65
+ font-size: 1.1rem;
66
+ color: #64748b;
67
+ margin-bottom: 20px;
68
+ }
69
  """
70
+
71
+ chatbot_interface = gr.ChatInterface(
 
72
  respond,
73
  type="messages",
74
+ title="✨ Le Chatbot qu'il vous faut", # Titre intégré
75
+ description="Une interface intelligente propulsée par DeepSeek AI.",
76
+
77
+ chatbot=gr.Chatbot(
78
+ height=500,
79
+ show_copy_button=True,
80
+ avatar_images=(None, "https://huggingface.co/datasets/huggingface/brand-assets/resolve/main/hf-logo.svg"), # (User, Bot)
81
+ bubble_full_width=False, # Bulles plus esthétiques
82
+ ),
83
+
84
  additional_inputs=[
85
+ gr.Textbox(value="You are a friendly Chatbot.", label="Message Système"),
 
86
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
87
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
88
+ gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
 
 
 
 
 
 
89
  ],
90
+ additional_inputs_accordion=gr.Accordion(label="⚙️ Paramètres avancés", open=False),
91
+
92
+ examples=[
93
+ ["Explique-moi la physique quantique simplement."],
94
+ ["Écris un poème sur l'intelligence artificielle."],
95
+ ["Comment faire une requête HTTP en Python ?"],
96
+ ],
97
+ cache_examples=False,
98
  )
99
 
100
+ with gr.Blocks(theme=custom_theme, css=custom_css, title="Mon Super Chatbot") as demo:
101
  with gr.Sidebar():
102
+ gr.Markdown("### 🔐 Authentification")
103
+ gr.LoginButton(value="Se connecter avec Hugging Face")
104
+ gr.Markdown("Connectez-vous pour accéder au modèle hébergé.")
105
+
106
+ chatbot_interface.render()
107
 
108
  if __name__ == "__main__":
109
+ demo.launch(share=True)