Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from llama_cpp import Llama | |
| from huggingface_hub import hf_hub_download | |
| import os | |
| # 1. Configuration & Auto-Download | |
| # The exact filename in the tiiuae repo is Falcon3-1B-Instruct-Q4_K_M.gguf | |
| try: | |
| MODEL_PATH = hf_hub_download( | |
| repo_id="tiiuae/Falcon3-1B-Instruct-GGUF", | |
| filename="Falcon3-1B-Instruct-Q4_K_M.gguf" | |
| ) | |
| except Exception: | |
| # Fallback in case of further naming discrepancies | |
| MODEL_PATH = hf_hub_download( | |
| repo_id="tiiuae/Falcon3-1B-Instruct-GGUF", | |
| filename="falcon3-1b-instruct-q4_k_m.gguf" | |
| ) | |
| # Initialize the Falcon model engine | |
| falcon_ai = Llama( | |
| model_path=MODEL_PATH, | |
| n_ctx=2048, | |
| n_threads=2, | |
| verbose=False | |
| ) | |
| def generate_falcon_ppt(topic, num_slides): | |
| if not topic: | |
| return "Please enter a topic to begin." | |
| prompt = f"""<|system|> | |
| You are an expert presentation designer. Create a PowerPoint script with EXACTLY {num_slides} slides. | |
| For each slide, include a Title, Bullet Points, and Speaker Notes. | |
| <|user|> | |
| Topic: {topic} | |
| Number of Slides: {num_slides} | |
| <|assistant|> | |
| """ | |
| output = falcon_ai( | |
| prompt, | |
| max_tokens=1500, | |
| stop=["<|endoftext|>", "<|user|>"], | |
| echo=False | |
| ) | |
| return output['choices'][0]['text'].strip() | |
| # 2. Gradio Interface Layout | |
| with gr.Blocks(theme=gr.themes.Soft()) as demo: | |
| gr.Markdown("# 🦅 Falcon3 Presentation Architect") | |
| gr.Markdown("Directly prompting the Falcon3-1B-Instruct model to build your slide deck.") | |
| with gr.Row(): | |
| with gr.Column(): | |
| topic_input = gr.Textbox( | |
| label="What is your presentation about?", | |
| placeholder="e.g., The history of space exploration", | |
| lines=2 | |
| ) | |
| slide_count = gr.Slider( | |
| minimum=1, | |
| maximum=12, | |
| step=1, | |
| value=5, | |
| label="Number of Slides Requested" | |
| ) | |
| submit_btn = gr.Button("Generate Falcon Script", variant="primary") | |
| with gr.Column(): | |
| output_display = gr.Textbox( | |
| label="Falcon3 Output", | |
| lines=18, | |
| show_copy_button=True | |
| ) | |
| submit_btn.click( | |
| fn=generate_falcon_ppt, | |
| inputs=[topic_input, slide_count], | |
| outputs=output_display | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |