Spaces:
Running
Running
Fix runtime error + add uncensored Zephyr model
Browse files
app.py
CHANGED
|
@@ -1,74 +1,31 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
top_p,
|
| 17 |
-
stream,
|
| 18 |
-
):
|
| 19 |
-
messages = [{"role": "system", "content": system_message}]
|
| 20 |
-
|
| 21 |
-
for val in history:
|
| 22 |
-
if val[0]:
|
| 23 |
-
messages.append({"role": "user", "content": val[0]})
|
| 24 |
-
if val[1]:
|
| 25 |
-
messages.append({"role": "assistant", "content": val[1]})
|
| 26 |
-
|
| 27 |
-
messages.append({"role": "user", "content": message})
|
| 28 |
-
|
| 29 |
-
response = ""
|
| 30 |
-
|
| 31 |
-
if stream:
|
| 32 |
-
for message in client.chat_completion(
|
| 33 |
-
messages,
|
| 34 |
-
max_tokens=max_tokens,
|
| 35 |
-
stream=stream,
|
| 36 |
-
temperature=temperature,
|
| 37 |
-
top_p=top_p,
|
| 38 |
-
):
|
| 39 |
-
token = message.choices[0].delta.content
|
| 40 |
-
|
| 41 |
-
response += token
|
| 42 |
-
yield response
|
| 43 |
-
else:
|
| 44 |
-
response = client.chat_completion(
|
| 45 |
-
messages,
|
| 46 |
-
max_tokens=max_tokens,
|
| 47 |
-
stream=stream,
|
| 48 |
-
temperature=temperature,
|
| 49 |
-
top_p=top_p,
|
| 50 |
)
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
| 55 |
demo = gr.ChatInterface(
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
gr.Slider(
|
| 62 |
-
minimum=0.1,
|
| 63 |
-
maximum=1.0,
|
| 64 |
-
value=0.95,
|
| 65 |
-
step=0.05,
|
| 66 |
-
label="Top-p (nucleus sampling)",
|
| 67 |
-
),
|
| 68 |
-
gr.Checkbox(label="Stream output", value=True),
|
| 69 |
-
],
|
| 70 |
)
|
| 71 |
|
| 72 |
-
|
| 73 |
if __name__ == "__main__":
|
| 74 |
-
demo.launch()
|
|
|
|
| 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()
|