Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from ctransformers import AutoModelForCausalLM
|
| 3 |
+
|
| 4 |
+
# ---------------------------------------------------------
|
| 5 |
+
# Load GGUF model (place the .gguf file in the Space repo)
|
| 6 |
+
# ---------------------------------------------------------
|
| 7 |
+
MODEL_PATH = "falcon3-1b-instruct-q4_k_m.gguf"
|
| 8 |
+
|
| 9 |
+
llm = AutoModelForCausalLM.from_pretrained(
|
| 10 |
+
MODEL_PATH,
|
| 11 |
+
model_type="falcon",
|
| 12 |
+
gpu_layers=0,
|
| 13 |
+
context_length=4096,
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
# ---------------------------------------------------------
|
| 17 |
+
# Prompt template
|
| 18 |
+
# ---------------------------------------------------------
|
| 19 |
+
SYSTEM_PROMPT = """
|
| 20 |
+
You are an expert instructional designer who writes clear,
|
| 21 |
+
engaging PowerPoint scripts with slide titles, bullet points,
|
| 22 |
+
and speaker notes.
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
def build_prompt(topic, slide_count):
|
| 26 |
+
return f"""{SYSTEM_PROMPT}
|
| 27 |
+
|
| 28 |
+
Write a complete PowerPoint script with EXACTLY {slide_count} slides.
|
| 29 |
+
|
| 30 |
+
Topic: {topic}
|
| 31 |
+
|
| 32 |
+
Return the output in this structure:
|
| 33 |
+
|
| 34 |
+
Title Slide:
|
| 35 |
+
- Title:
|
| 36 |
+
- Subtitle:
|
| 37 |
+
- Speaker Notes:
|
| 38 |
+
|
| 39 |
+
Slide 1:
|
| 40 |
+
- Slide Title:
|
| 41 |
+
- Bullet Points:
|
| 42 |
+
- Speaker Notes:
|
| 43 |
+
|
| 44 |
+
Slide 2:
|
| 45 |
+
- Slide Title:
|
| 46 |
+
- Bullet Points:
|
| 47 |
+
- Speaker Notes:
|
| 48 |
+
|
| 49 |
+
Continue until you reach Slide {slide_count}.
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
# ---------------------------------------------------------
|
| 53 |
+
# Generation function
|
| 54 |
+
# ---------------------------------------------------------
|
| 55 |
+
def generate_script(topic, slide_count, max_tokens, temperature, top_p):
|
| 56 |
+
if not topic:
|
| 57 |
+
return "Please enter a topic."
|
| 58 |
+
|
| 59 |
+
prompt = build_prompt(topic, slide_count)
|
| 60 |
+
|
| 61 |
+
output = ""
|
| 62 |
+
for token in llm(
|
| 63 |
+
prompt,
|
| 64 |
+
max_new_tokens=int(max_tokens),
|
| 65 |
+
temperature=float(temperature),
|
| 66 |
+
top_p=float(top_p),
|
| 67 |
+
stream=True,
|
| 68 |
+
):
|
| 69 |
+
output += token
|
| 70 |
+
|
| 71 |
+
return output.strip()
|
| 72 |
+
|
| 73 |
+
# ---------------------------------------------------------
|
| 74 |
+
# Gradio UI
|
| 75 |
+
# ---------------------------------------------------------
|
| 76 |
+
def build_ui():
|
| 77 |
+
with gr.Blocks(title="Falcon3‑1B PPT Script Generator") as demo:
|
| 78 |
+
gr.Markdown(
|
| 79 |
+
"""
|
| 80 |
+
# Falcon3‑1B‑Instruct‑GGUF
|
| 81 |
+
### PowerPoint Script Generator (Topic + Slide Count)
|
| 82 |
+
|
| 83 |
+
Provide a topic and the number of slides you want.
|
| 84 |
+
The model will generate a structured slide-by-slide script.
|
| 85 |
+
"""
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
with gr.Row():
|
| 89 |
+
with gr.Column():
|
| 90 |
+
topic = gr.Textbox(
|
| 91 |
+
label="Topic",
|
| 92 |
+
placeholder="e.g., AI Maturity Model"
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
slide_count = gr.Number(
|
| 96 |
+
label="Number of Slides",
|
| 97 |
+
value=8,
|
| 98 |
+
precision=0
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
max_tokens = gr.Slider(256, 4096, value=1500, label="Max Tokens")
|
| 102 |
+
temperature = gr.Slider(0.1, 1.5, value=0.7, label="Temperature")
|
| 103 |
+
top_p = gr.Slider(0.1, 1.0, value=0.9, label="Top‑p")
|
| 104 |
+
|
| 105 |
+
generate_btn = gr.Button("Generate Script")
|
| 106 |
+
|
| 107 |
+
with gr.Column():
|
| 108 |
+
output = gr.Markdown(label="Generated PowerPoint Script")
|
| 109 |
+
|
| 110 |
+
generate_btn.click(
|
| 111 |
+
generate_script,
|
| 112 |
+
inputs=[topic, slide_count, max_tokens, temperature, top_p],
|
| 113 |
+
outputs=output,
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
return demo
|
| 117 |
+
|
| 118 |
+
demo = build_ui()
|
| 119 |
+
|
| 120 |
+
if __name__ == "__main__":
|
| 121 |
+
demo.launch()
|