Kim465 commited on
Commit
255c46a
·
verified ·
1 Parent(s): 2200a8f

Update to new HF endpoint + chat_completion

Browse files
Files changed (1) hide show
  1. app.py +18 -14
app.py CHANGED
@@ -1,31 +1,35 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
 
3
 
4
- # Uncensored model ID
 
 
 
5
  model_id = "HuggingFaceH4/zephyr-7b-beta"
6
 
7
  def chat(message, history):
8
  try:
9
- client = InferenceClient(model=model_id)
10
- response = client.text_generation(
11
- message,
12
- max_new_tokens=200,
13
- temperature=0.8,
14
- do_sample=True,
15
- stop_sequences=["User:", "\n\n"]
16
  )
17
- return response
18
  except Exception as e:
19
- return f"Sorry, a quick glitch: {str(e)}. Try again!"
20
 
21
- # Simple uncensored chat interface
22
  demo = gr.ChatInterface(
23
  fn=chat,
24
  title="Uncensored AI Chatbot",
25
- description="No filters. Ask anything—dark jokes, opinions, anything!",
26
- examples=["Tell me a dark, uncensored joke.", "Roast me like a pirate.", "Give a controversial opinion on [topic]."],
27
  cache_examples=False
28
  )
29
 
30
  if __name__ == "__main__":
31
- demo.launch()
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
+ import os
4
 
5
+ # Your secret token
6
+ token = os.getenv("HF_TOKEN")
7
+
8
+ # Uncensored model
9
  model_id = "HuggingFaceH4/zephyr-7b-beta"
10
 
11
  def chat(message, history):
12
  try:
13
+ client = InferenceClient(token=token)
14
+ messages = [{"role": "user", "content": message}]
15
+ output = client.chat_completion(
16
+ messages,
17
+ model=model_id,
18
+ max_tokens=200,
19
+ temperature=0.8
20
  )
21
+ return output.choices[0].message.content
22
  except Exception as e:
23
+ return f"Sorry, glitch: {str(e)}. Try again!"
24
 
25
+ # Interface
26
  demo = gr.ChatInterface(
27
  fn=chat,
28
  title="Uncensored AI Chatbot",
29
+ description="No filters. Ask anything.",
30
+ examples=["Tell me a dark, uncensored joke.", "Roast me like a pirate."],
31
  cache_examples=False
32
  )
33
 
34
  if __name__ == "__main__":
35
+ demo.launch(auth=None)