Spaces:
Runtime error
Runtime error
File size: 1,569 Bytes
3643b73 dc09589 d591ad9 3643b73 d591ad9 a3606dd 3643b73 d591ad9 a3606dd d591ad9 dc09589 d591ad9 dc09589 d591ad9 |
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 27 28 29 30 31 32 33 34 35 36 37 |
import os
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM
access_token = os.environ["GATED_ACCESS_TOKEN"]
# Load the tokenizer and model
model_id = "mistralai/Mixtral-8x22B-v0.1"
tokenizer = AutoTokenizer.from_pretrained(model_id, token=access_token)
model = AutoModelForCausalLM.from_pretrained(model_id, token=access_token)
# Function to generate text using the model
def generate_text(prompt, max_length=500, temperature=0.7, top_k=50, top_p=0.95, num_return_sequences=1):
text = prompt
inputs = tokenizer(text, return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=20)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
# Create the Gradio interface
iface = gr.Interface(
fn=generate_text,
inputs=[
gr.inputs.Textbox(lines=5, label="Input Prompt"),
gr.inputs.Slider(minimum=100, maximum=1000, default=500, step=50, label="Max Length"),
gr.inputs.Slider(minimum=0.1, maximum=1.0, default=0.7, step=0.1, label="Temperature"),
gr.inputs.Slider(minimum=1, maximum=100, default=50, step=1, label="Top K"),
gr.inputs.Slider(minimum=0.1, maximum=1.0, default=0.95, step=0.05, label="Top P"),
gr.inputs.Slider(minimum=1, maximum=10, default=1, step=1, label="Num Return Sequences"),
],
outputs=gr.outputs.Textbox(label="Generated Text"),
title="MixTRAL 8x22B Text Generation",
description="Use this interface to generate text using the MixTRAL 8x22B language model.",
)
# Launch the Gradio interface
iface.launch() |