import gradio as gr from transformers import AutoTokenizer, AutoModelForCausalLM # Replace 'YOUR_ACCESS_TOKEN' with your actual Hugging Face access token model_name = "sambanovasystems/SambaNova-Qwen2.5-Coder-Artifacts" tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token='YOUR_ACCESS_TOKEN') model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token='YOUR_ACCESS_TOKEN') def generate_text(prompt): # Generate text using the model inputs = tokenizer.encode(prompt, return_tensors="pt") outputs = model.generate(inputs, max_length=100, num_return_sequences=1) text = tokenizer.decode(outputs[0], skip_special_tokens=True) return text # Build the Gradio interface with gr.Blocks() as demo: gr.Markdown("

AI Text Generator

") with gr.Row(): with gr.Column(): user_input = gr.Textbox(label="Input Prompt", placeholder="Enter your prompt here...") generate_btn = gr.Button("Generate Text") with gr.Column(): output_text = gr.Textbox(label="Generated Text", readonly=True) generate_btn.click(generate_text, inputs=user_input, outputs=output_text) # Launch the app demo.launch(share=True, theme="macos", css=".gradio-container {background-color: #f0f0f0;}")