Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,28 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
-
# Custom background CSS with
|
5 |
css = """
|
|
|
|
|
6 |
body {
|
7 |
background-image: url('https://cdn-uploads.huggingface.co/production/uploads/67351c643fe51cb1aa28f2e5/wuyd5UYTh9jPrMJGmV9yC.jpeg');
|
8 |
background-size: cover;
|
9 |
background-position: center;
|
10 |
background-repeat: no-repeat;
|
|
|
11 |
}
|
12 |
#chat-panel {
|
13 |
background-color: rgba(255, 255, 255, 0.85);
|
14 |
padding: 2rem;
|
15 |
border-radius: 12px;
|
16 |
max-width: 700px;
|
17 |
-
height:
|
18 |
margin: auto;
|
19 |
box-shadow: 0 0 12px rgba(0, 0, 0, 0.3);
|
20 |
overflow-y: auto;
|
21 |
}
|
22 |
-
|
23 |
color: #d63384 !important;
|
24 |
font-family: 'Playfair Display', serif !important;
|
25 |
font-size: 1.8rem !important;
|
@@ -28,6 +31,7 @@ body {
|
|
28 |
margin-bottom: 1rem !important;
|
29 |
}
|
30 |
"""
|
|
|
31 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
32 |
|
33 |
def respond(
|
@@ -39,13 +43,17 @@ def respond(
|
|
39 |
top_p,
|
40 |
):
|
41 |
messages = [{"role": "system", "content": system_message}]
|
|
|
42 |
for val in history:
|
43 |
if val[0]:
|
44 |
messages.append({"role": "user", "content": val[0]})
|
45 |
if val[1]:
|
46 |
messages.append({"role": "assistant", "content": val[1]})
|
|
|
47 |
messages.append({"role": "user", "content": message})
|
|
|
48 |
response = ""
|
|
|
49 |
for message in client.chat_completion(
|
50 |
messages,
|
51 |
max_tokens=max_tokens,
|
@@ -59,17 +67,21 @@ def respond(
|
|
59 |
|
60 |
with gr.Blocks(css=css) as demo:
|
61 |
with gr.Column(elem_id="chat-panel"):
|
|
|
|
|
62 |
with gr.Accordion("⚙️ Settings", open=False):
|
63 |
-
system_message = gr.Textbox(
|
|
|
|
|
|
|
64 |
max_tokens = gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens")
|
65 |
temperature = gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature")
|
66 |
top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)")
|
67 |
-
|
68 |
gr.ChatInterface(
|
69 |
respond,
|
70 |
-
title="🇫🇷 French Tutor", # Set title directly in ChatInterface
|
71 |
additional_inputs=[system_message, max_tokens, temperature, top_p]
|
72 |
)
|
73 |
|
74 |
if __name__ == "__main__":
|
75 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
+
# Custom background CSS with forced title styling
|
5 |
css = """
|
6 |
+
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP&family=Playfair+Display&display=swap');
|
7 |
+
|
8 |
body {
|
9 |
background-image: url('https://cdn-uploads.huggingface.co/production/uploads/67351c643fe51cb1aa28f2e5/wuyd5UYTh9jPrMJGmV9yC.jpeg');
|
10 |
background-size: cover;
|
11 |
background-position: center;
|
12 |
background-repeat: no-repeat;
|
13 |
+
font-family: 'Noto Sans JP', sans-serif;
|
14 |
}
|
15 |
#chat-panel {
|
16 |
background-color: rgba(255, 255, 255, 0.85);
|
17 |
padding: 2rem;
|
18 |
border-radius: 12px;
|
19 |
max-width: 700px;
|
20 |
+
height: 90vh;
|
21 |
margin: auto;
|
22 |
box-shadow: 0 0 12px rgba(0, 0, 0, 0.3);
|
23 |
overflow-y: auto;
|
24 |
}
|
25 |
+
.markdown-element h2 {
|
26 |
color: #d63384 !important;
|
27 |
font-family: 'Playfair Display', serif !important;
|
28 |
font-size: 1.8rem !important;
|
|
|
31 |
margin-bottom: 1rem !important;
|
32 |
}
|
33 |
"""
|
34 |
+
|
35 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
36 |
|
37 |
def respond(
|
|
|
43 |
top_p,
|
44 |
):
|
45 |
messages = [{"role": "system", "content": system_message}]
|
46 |
+
|
47 |
for val in history:
|
48 |
if val[0]:
|
49 |
messages.append({"role": "user", "content": val[0]})
|
50 |
if val[1]:
|
51 |
messages.append({"role": "assistant", "content": val[1]})
|
52 |
+
|
53 |
messages.append({"role": "user", "content": message})
|
54 |
+
|
55 |
response = ""
|
56 |
+
|
57 |
for message in client.chat_completion(
|
58 |
messages,
|
59 |
max_tokens=max_tokens,
|
|
|
67 |
|
68 |
with gr.Blocks(css=css) as demo:
|
69 |
with gr.Column(elem_id="chat-panel"):
|
70 |
+
gr.Markdown("## 🇯🇵 Japanese Tutor Chatbot")
|
71 |
+
|
72 |
with gr.Accordion("⚙️ Settings", open=False):
|
73 |
+
system_message = gr.Textbox(
|
74 |
+
value="You are an expert Japanese tutor. Help users understand Japanese grammar, vocabulary, sentence structure, particles, and kanji readings. Reply clearly in English unless the user specifies otherwise.",
|
75 |
+
label="System message"
|
76 |
+
)
|
77 |
max_tokens = gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens")
|
78 |
temperature = gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature")
|
79 |
top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)")
|
80 |
+
|
81 |
gr.ChatInterface(
|
82 |
respond,
|
|
|
83 |
additional_inputs=[system_message, max_tokens, temperature, top_p]
|
84 |
)
|
85 |
|
86 |
if __name__ == "__main__":
|
87 |
+
demo.launch()
|