File size: 5,565 Bytes
d79dc81 dabc240 d79dc81 dabc240 d79dc81 dabc240 d79dc81 dabc240 d79dc81 dabc240 d79dc81 dabc240 d79dc81 dabc240 d79dc81 dabc240 d79dc81 dabc240 d79dc81 dabc240 d79dc81 dabc240 d79dc81 dabc240 d79dc81 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Knowledge AI Studio β Nobel Literary & Werewolf Book Studio</title>
<meta name="description" content="Private AI co-writing and visual illustration workspace for crafting award-winning werewolf novels, book covers, and cinematic book trailers.">
<script type="module" crossorigin src="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.css" />
<style>
html, body {
margin: 0;
padding: 0;
height: 100%;
background-color: #f9fafb;
}
</style>
</head>
<body>
<gradio-lite>
<gradio-file name="app.py" entrypoint>
import gradio as gr
from huggingface_hub import InferenceClient
SYSTEM_PROMPT = (
"You are a master Nobel-caliber book writer and werewolf fiction co-author. "
"Write atmospheric, emotionally gripping, literary prose with rich world-building, "
"strictly maintaining pack lore and narrative continuity."
)
def write_chapter(prompt, history, hf_token, temp):
if not hf_token or not hf_token.strip():
return "π Please enter your Hugging Face Access Token in the top bar to start writing."
if not prompt or not prompt.strip():
return "Please enter a scene prompt or chapter instruction."
client = InferenceClient(token=hf_token.strip())
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
for user_msg, bot_msg in history:
messages.append({"role": "user", "content": user_msg})
messages.append({"role": "assistant", "content": bot_msg})
messages.append({"role": "user", "content": prompt})
try:
response = client.chat_completion(
model="inclusionAI/Ling-3.1-flash",
messages=messages,
max_tokens=2048,
temperature=temp,
)
return response.choices.message.content
except Exception as e:
return f"β οΈ Notice: {str(e)}"
def generate_scene_art(scene_prompt, hf_token):
if not hf_token or not hf_token.strip():
raise gr.Error("Please enter your Hugging Face Access Token in the top bar first.")
if not scene_prompt or not scene_prompt.strip():
return None
client = InferenceClient(token=hf_token.strip())
image = client.text_to_image(
prompt=f"Nobel literary book cover illustration, werewolf lore, cinematic natural lighting, clean painterly style, {scene_prompt}",
model="black-forest-labs/FLUX.1-schnell",
)
return image
def generate_book_trailer(video_prompt, hf_token):
if not hf_token or not hf_token.strip():
raise gr.Error("Please enter your Hugging Face Access Token in the top bar first.")
if not video_prompt or not video_prompt.strip():
return None
client = InferenceClient(token=hf_token.strip())
video_bytes = client.text_to_video(
prompt=f"Cinematic literary novel book trailer shot, luminous atmosphere, {video_prompt}",
model="Wan-AI/Wan2.1-T2V-14B",
)
output_path = "trailer_clip.mp4"
with open(output_path, "wb") as f:
f.write(video_bytes)
return output_path
with gr.Blocks(theme=gr.themes.Soft(), title="Knowledge AI Studio") as demo:
gr.Markdown("# π Knowledge AI Studio")
gr.Markdown("Nobel-caliber literary co-writing and visual studio powered by **Ling 3.1 Flash**, **FLUX.1**, and **Wan 2.1**.")
with gr.Accordion("π Author Access Key (Required)", open=True):
token_box = gr.Textbox(
label="Access Key",
type="password",
placeholder="Paste your hf_... access key here",
)
with gr.Tab("βοΈ Chapter & Lore Writer"):
temp_slider = gr.Slider(0.5, 1.2, value=0.9, label="Creativity (Temperature)")
gr.ChatInterface(
fn=write_chapter,
additional_inputs=[token_box, temp_slider],
examples=[
["Write an opening chapter where an ancient alpha discovers a forgotten treaty under a silver full moon.", "", 0.9],
["Create a rich cultural history and lineage for three noble werewolf clans.", "", 0.85],
],
)
with gr.Tab("π¨ Book Cover & Character Art"):
art_input = gr.Textbox(
label="Describe your character or scene",
placeholder="Silver-furred werewolf standing on a sunlit mountain ridge overlooking an ancient valley..."
)
art_btn = gr.Button("Generate Artwork", variant="primary")
art_output = gr.Image(label="Generated Book Art")
art_btn.click(fn=generate_scene_art, inputs=[art_input, token_box], outputs=art_output)
with gr.Tab("π¬ Book Trailer Video"):
vid_input = gr.Textbox(
label="Describe the trailer motion scene",
placeholder="Slow sweeping camera through a misty northern pine forest at dawn..."
)
vid_btn = gr.Button("Generate Video Clip", variant="primary")
vid_output = gr.Video(label="Generated Trailer Clip")
vid_btn.click(fn=generate_book_trailer, inputs=[vid_input, token_box], outputs=vid_output)
demo.launch()
</gradio-file>
<gradio-requirements>
huggingface-hub>=0.26.0
</gradio-requirements>
</gradio-lite>
</body>
</html> |