Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
|
| 4 |
+
# Load the model and tokenizer
|
| 5 |
+
model_name = "facebook/chameleon-7b"
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 8 |
+
|
| 9 |
+
# Function to generate response
|
| 10 |
+
def generate_response(input_text):
|
| 11 |
+
inputs = tokenizer(input_text, return_tensors="pt")
|
| 12 |
+
outputs = model.generate(inputs.input_ids, max_length=500, num_return_sequences=1)
|
| 13 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 14 |
+
return response
|
| 15 |
+
|
| 16 |
+
# Custom CSS
|
| 17 |
+
css = """
|
| 18 |
+
body {
|
| 19 |
+
background-color: #2e3440;
|
| 20 |
+
color: #d8dee9;
|
| 21 |
+
font-family: 'Roboto', sans-serif;
|
| 22 |
+
}
|
| 23 |
+
.gradio-container {
|
| 24 |
+
background-color: #3b4252;
|
| 25 |
+
border: 2px solid #88c0d0;
|
| 26 |
+
border-radius: 10px;
|
| 27 |
+
padding: 20px;
|
| 28 |
+
}
|
| 29 |
+
.gr-button {
|
| 30 |
+
background-color: #5e81ac;
|
| 31 |
+
color: #d8dee9;
|
| 32 |
+
border-radius: 5px;
|
| 33 |
+
}
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
+
# Define the Gradio interface
|
| 37 |
+
with gr.Blocks(css=css) as demo:
|
| 38 |
+
gr.Markdown("# Chat with Chameleon-7B", elem_id="header")
|
| 39 |
+
with gr.Row():
|
| 40 |
+
with gr.Column():
|
| 41 |
+
input_text = gr.Textbox(label="Your Input", placeholder="Type your message here...", lines=4)
|
| 42 |
+
output_text = gr.Textbox(label="Chameleon-7B Response", placeholder="The model's response will appear here...", lines=4)
|
| 43 |
+
submit_button = gr.Button("Submit")
|
| 44 |
+
with gr.Column():
|
| 45 |
+
gr.Markdown("### Instructions")
|
| 46 |
+
gr.Markdown("Enter your message in the input box and press submit to get a response from Chameleon-7B.")
|
| 47 |
+
submit_button.click(fn=generate_response, inputs=input_text, outputs=output_text)
|
| 48 |
+
|
| 49 |
+
# Launch the Gradio app
|
| 50 |
+
demo.launch()
|