Spaces:
Runtime error
Runtime error
Update app.py
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950import gradio as grfrom transformers import AutoModelForCausalLM, AutoTokenizer
# Load the model and tokenizermodel_name = "facebook/chameleon-7b"tokenizer = AutoTokenizer.from_pretrained(model_name)model = AutoModelForCausalLM.from_pretrained(model_name)
# Function to generate responsedef generate_response(input_text): inputs = tokenizer(input_text, return_tensors="pt") outputs = model.generate(inputs.input_ids, max_length=500, num_return_sequences=1) response = tokenizer.decode(outputs[0], skip_special_tokens=True) return response
# Custom CSScss = """body { background-color: #2e3440; color: #d8dee9; font-family: 'Roboto', sans-serif;}.gradio-container { background-color: #3b4252; border: 2px solid #88c0d0; border-radius: 10px; padding: 20px;}.gr-button { background-color: #5e81ac; color: #d8dee9; border-radius: 5px;}"""
# Define the Gradio interfacewith gr.Blocks(css=css) as demo: gr.Markdown("# Chat with Chameleon-7B", elem_id="header") with gr.Row(): with gr.Column(): input_text = gr.Textbox(label="Your Input", placeholder="Type your message here...", lines=4) output_text = gr.Textbox(label="Chameleon-7B Response", placeholder="The model's response will appear here...", lines=4) submit_button = gr.Button("Submit") with gr.Column(): gr.Markdown("### Instructions") gr.Markdown("Enter your message in the input box and press submit to get a response from Chameleon-7B.") submit_button.click(fn=generate_response, inputs=input_text, outputs=output_text)
# Launch the Gradio appdemo.launch()app.py+50