Spaces:
Runtime error
Runtime error
File size: 961 Bytes
7c2904b 4be8187 7c2904b 4be8187 d896de4 74a0653 d896de4 e55a05c 7c2904b e55a05c d896de4 7c2904b e55a05c |
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 |
import gradio as gr
from transformers import pipeline, AutoConfig
# Explicitly load the configuration with trust_remote_code
config = AutoConfig.from_pretrained('tiiuae/falcon-40b-instruct', trust_remote_code=True)
# Load the model once when the script starts using the loaded config
generator = pipeline('text-generation', model='tiiuae/falcon-40b-instruct', config=config)
def generate_text(prompt):
# Use the preloaded model
return generator(prompt, max_length=100)[0]['generated_text']
def main():
with gr.Blocks() as demo:
gr.Markdown("## Text Generation Model")
gr.Markdown("This model generates text based on the input prompt. Powered by Hugging Face transformers.")
prompt = gr.Textbox(lines=2, placeholder="Type your prompt here...")
output = gr.Text(label="Generated Text")
prompt.change(fn=generate_text, inputs=prompt, outputs=output)
demo.launch()
if __name__ == "__main__":
main() |