drwlf commited on
Commit
7f97613
·
verified ·
1 Parent(s): 2dd258a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -99
app.py CHANGED
@@ -86,102 +86,3 @@ def respond(
86
  # Potential cleanup if required by the library, often not needed explicitly
87
  pass
88
 
89
-
90
- """
91
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
92
- """
93
- demo = gr.ChatInterface(
94
- respond,
95
- chatbot=gr.Chatbot(height=500), # Set chatbot height
96
- additional_inputs=[
97
- gr.Textbox(value="You are a friendly psychotherapy AI capable of thinking.", label="System message"),
98
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
99
- gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.1, label="Temperature"), # Adjusted max temp based on common usage
100
- gr.Slider(
101
- minimum=0.05, # Min Top-P often > 0
102
- maximum=1.0,
103
- value=0.95,
104
- step=0.05,
105
- label="Top-P (nucleus sampling)",
106
- ),
107
- # Added Top-K slider
108
- gr.Slider(
109
- minimum=0, # 0 disables Top-K
110
- maximum=100, # Common range, adjust if needed
111
- value=0, # Default to disabled
112
- step=1,
113
- label="Top-K (0 = disabled)",
114
- ),
115
- ],
116
- title="PsychoQwen Chat",
117
- description=f"Chat with {MODEL_ID}. Adjust generation parameters below.",
118
- retry_btn="Retry",
119
- undo_btn="Undo",
120
- clear_btn="Clear Chat",
121
- )
122
-
123
-
124
- if __name__ == "__main__":
125
- demo.queue().launch(debug=True) # Add queue() for streaming
126
-
127
- """
128
- 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
129
- """
130
- client = InferenceClient("drwlf/PsychoQwen14b")
131
-
132
-
133
- def respond(
134
- message,
135
- history: list[tuple[str, str]],
136
- system_message,
137
- max_tokens,
138
- temperature,
139
- top_p,
140
- ):
141
- messages = [{"role": "system", "content": system_message}]
142
-
143
- for val in history:
144
- if val[0]:
145
- messages.append({"role": "user", "content": val[0]})
146
- if val[1]:
147
- messages.append({"role": "assistant", "content": val[1]})
148
-
149
- messages.append({"role": "user", "content": message})
150
-
151
- response = ""
152
-
153
- for message in client.chat_completion(
154
- messages,
155
- max_tokens=max_tokens,
156
- stream=True,
157
- temperature=temperature,
158
- top_p=top_p,
159
- ):
160
- token = message.choices[0].delta.content
161
-
162
- response += token
163
- yield response
164
-
165
-
166
- """
167
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
168
- """
169
- demo = gr.ChatInterface(
170
- respond,
171
- additional_inputs=[
172
- gr.Textbox(value="You are a friendly psychotherapy AI capable of thinking.", label="System message"),
173
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
174
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
175
- gr.Slider(
176
- minimum=0.1,
177
- maximum=1.0,
178
- value=0.95,
179
- step=0.05,
180
- label="Top-p (nucleus sampling)",
181
- ),
182
- ],
183
- )
184
-
185
-
186
- if __name__ == "__main__":
187
- demo.launch()
 
86
  # Potential cleanup if required by the library, often not needed explicitly
87
  pass
88