Spaces:
Paused
Paused
Updated Gemma chatbot
Browse files- Tabs/Gemma_Chatbot.py +82 -0
- app.py +3 -4
Tabs/Gemma_Chatbot.py
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from huggingface_hub import InferenceClient
|
3 |
+
import os
|
4 |
+
from dotenv import load_dotenv
|
5 |
+
|
6 |
+
load_dotenv()
|
7 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
8 |
+
|
9 |
+
model_list = ["google/gemma-2-2b-it", "google/gemma-2-9b-it", "google/gemma-2-27b-it"]
|
10 |
+
|
11 |
+
def respond(
|
12 |
+
message,
|
13 |
+
history: list[tuple[str, str]],
|
14 |
+
model_id,
|
15 |
+
system_message,
|
16 |
+
max_tokens,
|
17 |
+
temperature,
|
18 |
+
top_p,
|
19 |
+
):
|
20 |
+
client = InferenceClient(
|
21 |
+
model_id,
|
22 |
+
token=HF_TOKEN,
|
23 |
+
)
|
24 |
+
messages = [{"role": "system", "content": system_message}]
|
25 |
+
|
26 |
+
for val in history:
|
27 |
+
if val[0]:
|
28 |
+
messages.append({"role": "user", "content": val[0]})
|
29 |
+
if val[1]:
|
30 |
+
messages.append({"role": "assistant", "content": val[1]})
|
31 |
+
|
32 |
+
messages.append({"role": "user", "content": message})
|
33 |
+
|
34 |
+
response = ""
|
35 |
+
|
36 |
+
for message in client.chat_completion(
|
37 |
+
messages,
|
38 |
+
max_tokens=max_tokens,
|
39 |
+
stream=True,
|
40 |
+
temperature=temperature,
|
41 |
+
top_p=top_p,
|
42 |
+
):
|
43 |
+
token = message.choices[0].delta.content
|
44 |
+
|
45 |
+
response += token
|
46 |
+
yield response
|
47 |
+
|
48 |
+
gemma_chatbot = gr.ChatInterface(
|
49 |
+
respond,
|
50 |
+
additional_inputs=[
|
51 |
+
gr.Dropdown(
|
52 |
+
choices=model_list,
|
53 |
+
label="Model",
|
54 |
+
value="google/gemma-2-27b-it",
|
55 |
+
),
|
56 |
+
gr.Textbox(
|
57 |
+
value="You are a friendly Chatbot.",
|
58 |
+
label="System message"
|
59 |
+
),
|
60 |
+
gr.Slider(
|
61 |
+
minimum=1,
|
62 |
+
maximum=4096,
|
63 |
+
value=512,
|
64 |
+
step=1,
|
65 |
+
label="Max new tokens"
|
66 |
+
),
|
67 |
+
gr.Slider(
|
68 |
+
minimum=0.1,
|
69 |
+
maximum=4.0,
|
70 |
+
value=0.7,
|
71 |
+
step=0.1,
|
72 |
+
label="Temperature"
|
73 |
+
),
|
74 |
+
gr.Slider(
|
75 |
+
minimum=0.1,
|
76 |
+
maximum=1.0,
|
77 |
+
value=0.95,
|
78 |
+
step=0.05,
|
79 |
+
label="Top-p (nucleus sampling)",
|
80 |
+
),
|
81 |
+
],
|
82 |
+
)
|
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
from Tabs.Gemini_Chabot_Stable import gemini_chatbot, clear_chat_button, undo_chat_button, clear_chat_history, undo_chat, TITLE, NOTICE, ERRORS, FUTURE_IMPLEMENTATIONS, ABOUT
|
3 |
from Tabs.Gemini_Chatbot_Preview import gemini_chatbot_preview, clear_chat_button_preview, undo_chat_button_preview, clear_chat_history_preview, undo_chat_preview
|
|
|
4 |
|
5 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
6 |
gr.HTML("""<h3 align="center">I strongly recommond duplicating this space for intensive uses!!!</h3>""")
|
@@ -20,10 +21,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
20 |
fn=undo_chat
|
21 |
)
|
22 |
# ============================== Stable - END ==============================
|
23 |
-
|
24 |
-
with gr.Tab("Chat with Gemma 2"):
|
25 |
-
gr.HTML("""<h1 align="center">Still in development</h1>""")
|
26 |
-
|
27 |
# ============================== Nightly - START ==============================
|
28 |
with gr.Tab("Chat with Gemini 1.5 - Preview"):
|
29 |
gemini_chatbot_preview.render()
|
@@ -34,5 +31,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
34 |
fn=undo_chat_preview
|
35 |
)
|
36 |
# ============================== Nightly - END ==============================
|
|
|
|
|
37 |
|
38 |
demo.queue().launch(debug=True, show_error=True)
|
|
|
1 |
import gradio as gr
|
2 |
from Tabs.Gemini_Chabot_Stable import gemini_chatbot, clear_chat_button, undo_chat_button, clear_chat_history, undo_chat, TITLE, NOTICE, ERRORS, FUTURE_IMPLEMENTATIONS, ABOUT
|
3 |
from Tabs.Gemini_Chatbot_Preview import gemini_chatbot_preview, clear_chat_button_preview, undo_chat_button_preview, clear_chat_history_preview, undo_chat_preview
|
4 |
+
from Tabs.Gemma_Chatbot import gemma_chatbot
|
5 |
|
6 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
7 |
gr.HTML("""<h3 align="center">I strongly recommond duplicating this space for intensive uses!!!</h3>""")
|
|
|
21 |
fn=undo_chat
|
22 |
)
|
23 |
# ============================== Stable - END ==============================
|
|
|
|
|
|
|
|
|
24 |
# ============================== Nightly - START ==============================
|
25 |
with gr.Tab("Chat with Gemini 1.5 - Preview"):
|
26 |
gemini_chatbot_preview.render()
|
|
|
31 |
fn=undo_chat_preview
|
32 |
)
|
33 |
# ============================== Nightly - END ==============================
|
34 |
+
with gr.Tab("Chat with Gemma 2"):
|
35 |
+
gemma_chatbot.render()
|
36 |
|
37 |
demo.queue().launch(debug=True, show_error=True)
|