Spaces:
Sleeping
Sleeping
update app.py
Browse files
app.py
CHANGED
@@ -3,12 +3,11 @@ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
|
3 |
|
4 |
# Define the function to handle text generation
|
5 |
def generate_text(model_name, text, num_beams, max_length, top_p, temperature, repetition_penalty, no_repeat_ngram_size):
|
6 |
-
# Load tokenizer and model
|
7 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
9 |
|
10 |
-
# Initialize pipeline
|
11 |
-
pipe = pipeline("text-generation", model=
|
12 |
|
13 |
# Generate text with the specified parameters
|
14 |
generated_text = pipe(text,
|
@@ -18,22 +17,17 @@ def generate_text(model_name, text, num_beams, max_length, top_p, temperature, r
|
|
18 |
top_p=top_p,
|
19 |
temperature=temperature,
|
20 |
repetition_penalty=repetition_penalty,
|
21 |
-
no_repeat_ngram_size=no_repeat_ngram_size
|
|
|
22 |
|
23 |
return generated_text
|
24 |
|
25 |
-
# Define model options
|
26 |
-
model_options = [
|
27 |
-
"riotu-lab/ArabianGPT-01B",
|
28 |
-
"riotu-lab/ArabianGPT-03B",
|
29 |
-
"riotu-lab/ArabianGPT-08B"
|
30 |
-
]
|
31 |
-
|
32 |
-
# Define Gradio interface components
|
33 |
inputs_component = [
|
34 |
gr.Dropdown(choices=model_options, label="Select Model"),
|
35 |
gr.Textbox(lines=2, placeholder="Enter your text here...", label="Input Text"),
|
36 |
-
gr.Slider(minimum=1, maximum=10, step=1,
|
37 |
gr.Slider(minimum=50, maximum=300, step=10, label="Max Length"),
|
38 |
gr.Slider(minimum=0.0, maximum=1.0, step=0.1, label="Top p"),
|
39 |
gr.Slider(minimum=0.0, maximum=1.0, step=0.1, label="Temperature"),
|
@@ -41,14 +35,14 @@ inputs_component = [
|
|
41 |
gr.Slider(minimum=2, maximum=5, step=1, label="No Repeat Ngram Size")
|
42 |
]
|
43 |
|
44 |
-
# Setup the interface
|
45 |
iface = gr.Interface(
|
46 |
fn=generate_text,
|
47 |
inputs=inputs_component,
|
48 |
outputs="text",
|
49 |
title="ArabianGPT Playground",
|
50 |
description="Explore the capabilities of ArabianGPT models. Adjust the hyperparameters to see how they affect text generation.",
|
51 |
-
live=False
|
52 |
)
|
53 |
|
54 |
# Launch the app
|
|
|
3 |
|
4 |
# Define the function to handle text generation
|
5 |
def generate_text(model_name, text, num_beams, max_length, top_p, temperature, repetition_penalty, no_repeat_ngram_size):
|
|
|
6 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
|
9 |
+
# Initialize pipeline with explicit model and tokenizer
|
10 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
11 |
|
12 |
# Generate text with the specified parameters
|
13 |
generated_text = pipe(text,
|
|
|
17 |
top_p=top_p,
|
18 |
temperature=temperature,
|
19 |
repetition_penalty=repetition_penalty,
|
20 |
+
no_repeat_ngram_size=no_repeat_ngram_size,
|
21 |
+
truncation=True)[0]['generated_text'] # Added truncation=True explicitly
|
22 |
|
23 |
return generated_text
|
24 |
|
25 |
+
# Define model options and interface components
|
26 |
+
model_options = ["riotu-lab/ArabianGPT-01B", "riotu-lab/ArabianGPT-03B", "riotu-lab/ArabianGPT-08B"]
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
inputs_component = [
|
28 |
gr.Dropdown(choices=model_options, label="Select Model"),
|
29 |
gr.Textbox(lines=2, placeholder="Enter your text here...", label="Input Text"),
|
30 |
+
gr.Slider(minimum=1, maximum=10, step=1, label="Num Beams"),
|
31 |
gr.Slider(minimum=50, maximum=300, step=10, label="Max Length"),
|
32 |
gr.Slider(minimum=0.0, maximum=1.0, step=0.1, label="Top p"),
|
33 |
gr.Slider(minimum=0.0, maximum=1.0, step=0.1, label="Temperature"),
|
|
|
35 |
gr.Slider(minimum=2, maximum=5, step=1, label="No Repeat Ngram Size")
|
36 |
]
|
37 |
|
38 |
+
# Setup the interface with live=False to require button press
|
39 |
iface = gr.Interface(
|
40 |
fn=generate_text,
|
41 |
inputs=inputs_component,
|
42 |
outputs="text",
|
43 |
title="ArabianGPT Playground",
|
44 |
description="Explore the capabilities of ArabianGPT models. Adjust the hyperparameters to see how they affect text generation.",
|
45 |
+
live=False # Requires user to press "submit" to run
|
46 |
)
|
47 |
|
48 |
# Launch the app
|