CCockrum commited on
Commit
c65c64a
·
verified ·
1 Parent(s): 2137fcc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -42
app.py CHANGED
@@ -1,82 +1,71 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
- # Custom background CSS with styled title and panel
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/GdA9eNQKjOQjE6q47km3l.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
- #.gradio-container .chatbot .header {
26
- color: #c785a0; !important;
27
- font-family: 'Noto Sans', serif !important;
28
- font-size: 1.8rem !important;
29
- font-weight: bold !important;
30
- text-align: center !important;
31
- margin-bottom: 1rem !important;
32
- }
33
  """
34
 
35
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
36
 
37
- def respond(
38
- message,
39
- history: list[tuple[str, str]],
40
- system_message,
41
- max_tokens,
42
- temperature,
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,
60
  stream=True,
61
- temperature=temperature,
62
- top_p=top_p,
63
  ):
64
  token = message.choices[0].delta.content
65
  response += token
66
  yield response
67
 
68
  with gr.Blocks(css=css) as demo:
 
 
 
69
  with gr.Column(elem_id="chat-panel"):
70
- gr.Markdown("## 🇯🇵 Japanese Instructor", elem_id="chat-title")
71
-
72
- with gr.Accordion("⚙️ Settings", open=False):
73
- max_tokens = gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Response Length")
74
- temperature = gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Response Creativity")
75
-
76
- gr.ChatInterface(
77
- respond,
78
- additional_inputs=[max_tokens, temperature]
79
- )
80
 
81
  if __name__ == "__main__":
82
- demo.launch()
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
+ # Custom background CSS with semi-transparent panel
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
+
13
+ .gradio-container {
14
+ display: flex;
15
+ flex-direction: column;
16
+ justify-content: center;
17
+ align-items: center;
18
+ min-height: 100vh;
19
+ padding-top: 2rem;
20
+ padding-bottom: 2rem;
21
+ }
22
+
23
+ #custom-title {
24
+ color: #d63384;
25
+ font-family: 'Playfair Display', serif;
26
+ font-size: 2.5rem;
27
+ font-weight: bold;
28
+ text-align: center;
29
+ margin-bottom: 20px;
30
+ }
31
+
32
  #chat-panel {
33
  background-color: rgba(255, 255, 255, 0.85);
34
  padding: 2rem;
35
  border-radius: 12px;
36
+ width: 100%;
37
  max-width: 700px;
38
+ height: 70vh;
 
39
  box-shadow: 0 0 12px rgba(0, 0, 0, 0.3);
40
  overflow-y: auto;
41
  }
 
 
 
 
 
 
 
 
42
  """
43
 
44
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
45
 
46
+ def respond(message, history):
47
+ messages = [{"role": "system", "content": "You are a helpful French tutor."}]
 
 
 
 
 
 
 
 
48
  for val in history:
49
  if val[0]:
50
  messages.append({"role": "user", "content": val[0]})
51
  if val[1]:
52
  messages.append({"role": "assistant", "content": val[1]})
 
53
  messages.append({"role": "user", "content": message})
 
54
  response = ""
 
55
  for message in client.chat_completion(
56
  messages,
 
57
  stream=True,
 
 
58
  ):
59
  token = message.choices[0].delta.content
60
  response += token
61
  yield response
62
 
63
  with gr.Blocks(css=css) as demo:
64
+ # Title Markdown block
65
+ gr.Markdown("# 🇫🇷 French Tutor", elem_id="custom-title")
66
+
67
  with gr.Column(elem_id="chat-panel"):
68
+ gr.ChatInterface(respond)
 
 
 
 
 
 
 
 
 
69
 
70
  if __name__ == "__main__":
71
+ demo.launch()