SHAMIL SHAHBAZ AWAN commited on
Commit
722b6b6
·
verified ·
1 Parent(s): 2d5862b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +77 -22
app.py CHANGED
@@ -1,12 +1,10 @@
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]],
@@ -40,25 +38,82 @@ 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
- 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
 
4
+ # Initialize the Hugging Face Inference Client
 
 
5
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
6
 
7
+ # Function to handle chatbot responses
8
  def respond(
9
  message,
10
  history: list[tuple[str, str]],
 
38
  yield response
39
 
40
 
41
+ # Gradio Interface with UI Customization
42
+ with gr.Blocks(theme="soft") as demo:
43
+ gr.HTML(
44
+ """
45
+ <div style="background-color: #f0f4ff; padding: 10px; border-radius: 10px; text-align: center;">
46
+ <h1 style="color: #4a90e2;">AI Chat Interface</h1>
47
+ <p style="font-size: 16px; color: #4a4a4a;">
48
+ Powered by Hugging Face's Zephyr-7B model. Customize your system message and parameters for a tailored chat experience.
49
+ </p>
50
+ </div>
51
+ """
52
+ )
53
+
54
+ with gr.Row():
55
+ with gr.Column(scale=2):
56
+ chat = gr.ChatInterface(
57
+ respond,
58
+ additional_inputs=[
59
+ gr.Textbox(
60
+ value="You are a friendly Chatbot.",
61
+ label="System message",
62
+ lines=2,
63
+ max_lines=3,
64
+ interactive=True,
65
+ elem_id="system_message_box",
66
+ ),
67
+ gr.Slider(
68
+ minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"
69
+ ),
70
+ gr.Slider(
71
+ minimum=0.1,
72
+ maximum=4.0,
73
+ value=0.7,
74
+ step=0.1,
75
+ label="Temperature",
76
+ ),
77
+ gr.Slider(
78
+ minimum=0.1,
79
+ maximum=1.0,
80
+ value=0.95,
81
+ step=0.05,
82
+ label="Top-p (nucleus sampling)",
83
+ ),
84
+ ],
85
+ )
86
+ with gr.Column(scale=1):
87
+ gr.HTML(
88
+ """
89
+ <div style="background-color: #eaf4f4; padding: 15px; border-radius: 10px;">
90
+ <h3 style="color: #2c7873;">Tips for Better Interaction:</h3>
91
+ <ul style="font-size: 14px; color: #4a4a4a;">
92
+ <li>Provide clear and concise messages for optimal responses.</li>
93
+ <li>Adjust the <strong>Temperature</strong> for more creative or focused answers.</li>
94
+ <li>Use <strong>Top-p</strong> for better control over randomness in responses.</li>
95
+ </ul>
96
+ </div>
97
+ """
98
+ )
99
 
100
+ # Styling the background
101
+ demo.css = """
102
+ body {
103
+ background-color: #f9fafb;
104
+ }
105
+ .gr-textbox {
106
+ border: 1px solid #e1e4e8;
107
+ border-radius: 5px;
108
+ }
109
+ #system_message_box {
110
+ border: 2px dashed #4a90e2;
111
+ background-color: #f0f9ff;
112
+ }
113
+ .gr-slider {
114
+ background-color: #e9f7fc;
115
+ }
116
+ """
117
 
118
  if __name__ == "__main__":
119
  demo.launch()