File size: 2,143 Bytes
2a5a75a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
829dadb
 
 
 
 
 
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
52
53
54
55
56
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):
    # Load tokenizer and model
    tokenizer = AutoTokenizer.from_pretrained(model_name)
    model = AutoModelForCausalLM.from_pretrained(model_name)
    
    # Initialize pipeline
    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)[0]['generated_text']
    
    return generated_text

# Define model options
model_options = [
    "riotu-lab/ArabianGPT-01B",
    "riotu-lab/ArabianGPT-03B",
    "riotu-lab/ArabianGPT-08B"
]

# Define Gradio interface components
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.0, maximum=1.0, step=0.1, label="Top p"),
    gr.Slider(minimum=0.0, 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")
]

# Setup the interface
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=True
)

# Launch the app
iface.launch()