File size: 2,448 Bytes
2a5a75a
 
 
 
618d911
 
 
2a5a75a
950ec67
 
2a5a75a
 
 
 
 
 
 
 
 
950ec67
 
2a5a75a
 
 
950ec67
a3871d3
2a5a75a
 
 
950ec67
829dadb
08e5370
 
829dadb
618d911
 
2a5a75a
 
950ec67
2a5a75a
 
 
 
 
 
950ec67
2a5a75a
 
 
 
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline

# Define the function to handle text generation
def generate_text(model_name, text, num_beams, max_length, top_p, temperature, repetition_penalty, no_repeat_ngram_size, token):
    tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=token)
    model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=token)
    
    # Initialize pipeline with explicit model and tokenizer
    pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
    
    # Generate text with the specified parameters
    generated_text = pipe(text,
                          pad_token_id=tokenizer.eos_token_id,
                          num_beams=num_beams,
                          max_length=max_length,
                          top_p=top_p,
                          temperature=temperature,
                          repetition_penalty=repetition_penalty,
                          no_repeat_ngram_size=no_repeat_ngram_size,
                          truncation=True)[0]['generated_text']  # Added truncation=True explicitly
    
    return generated_text

# Define model options and interface components
model_options = ["riotu-lab/ArabianGPT-01B", "riotu-lab/ArabianGPT-03B", "riotu-lab/ArabianGPT-08B-V2"]
inputs_component = [
    gr.Dropdown(choices=model_options, label="Select Model"),
    gr.Textbox(lines=2, placeholder="Enter your text here...", label="Input Text"),
    gr.Slider(minimum=1, maximum=10, step=1, label="Num Beams"),
    gr.Slider(minimum=50, maximum=300, step=10, label="Max Length"),
    gr.Slider(minimum=0.1, maximum=1.0, step=0.1, label="Top p"),
    gr.Slider(minimum=0.1, maximum=1.0, step=0.1, label="Temperature"),
    gr.Slider(minimum=1.0, maximum=5.0, step=0.5, label="Repetition Penalty"),
    gr.Slider(minimum=2, maximum=5, step=1, label="No Repeat Ngram Size"),
    gr.Textbox(placeholder="Enter your Hugging Face token here...", label="Hugging Face Token", type="password")
]

# Setup the interface with live=False to require button press
iface = gr.Interface(
    fn=generate_text,
    inputs=inputs_component,
    outputs="text",
    title="ArabianGPT Playground",
    description="Explore the capabilities of ArabianGPT models. Adjust the hyperparameters to see how they affect text generation.",
    live=False  # Requires user to press "submit" to run
)

# Launch the app
iface.launch()