huggingface_hub
import gradio as gr
from huggingface_hub import InferenceClient
text_client = InferenceClient("failspy/Llama-3-8B-Instruct-Abliterated")
image_client = InferenceClient("black-forest-labs/FLUX.1-schnell")
def chat(message, history):
if any(k in message.lower() for k in ["draw", "image of", "generate image"]):
p = message.replace("draw", "").replace("generate image of", "").replace("image of", "").strip()
try:
img = image_client.text_to_image(p)
return [("Here is your image:", img)]
except Exception:
return [("Image generation failed.", None)]
try:
res = ""
for token in text_client.chat_completion([{"role": "user", "content": message}], stream=True):
res += token.choices[0].delta.content
return [(res, None)]
except Exception:
return [("Could not reach model.", None)]
with gr.Blocks() as demo:
gr.Markdown("### Uncensored Chat & Image Maker")
b = gr.Chatbot()
m = gr.Textbox(placeholder="Talk or type 'draw [description]'...")
def respond(usr, hist):
out = chat(usr, hist)
hist.append((usr, out[0][0]))
if out[0][1]:
hist.append((None, out[0][1]))
return "", hist
m.submit(respond, [m, b], [m, b])
demo.launch()