Spaces:
Running
Running
Update to new HF endpoint + chat_completion
Browse files
app.py
CHANGED
|
@@ -1,31 +1,35 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
|
|
|
| 3 |
|
| 4 |
-
#
|
|
|
|
|
|
|
|
|
|
| 5 |
model_id = "HuggingFaceH4/zephyr-7b-beta"
|
| 6 |
|
| 7 |
def chat(message, history):
|
| 8 |
try:
|
| 9 |
-
client = InferenceClient(
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
)
|
| 17 |
-
return
|
| 18 |
except Exception as e:
|
| 19 |
-
return f"Sorry,
|
| 20 |
|
| 21 |
-
#
|
| 22 |
demo = gr.ChatInterface(
|
| 23 |
fn=chat,
|
| 24 |
title="Uncensored AI Chatbot",
|
| 25 |
-
description="No filters. Ask anything
|
| 26 |
-
examples=["Tell me a dark, uncensored joke.", "Roast me like a pirate."
|
| 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)
|