Update app.py
Browse files
app.py
CHANGED
@@ -16,29 +16,29 @@ model_name = "meta-llama/Llama-3.2-1B"
|
|
16 |
tokenizer = AutoTokenizer.from_pretrained(model_name, token=api_token)
|
17 |
model = AutoModelForCausalLM.from_pretrained(model_name, token=api_token)
|
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 |
-
|
|
|
16 |
tokenizer = AutoTokenizer.from_pretrained(model_name, token=api_token)
|
17 |
model = AutoModelForCausalLM.from_pretrained(model_name, token=api_token)
|
18 |
|
19 |
+
# Define the function to generate text
|
20 |
+
def generate_text(prompt, max_length=100, temperature=0.7):
|
21 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
22 |
+
output = model.generate(
|
23 |
+
inputs['input_ids'],
|
24 |
+
max_length=max_length,
|
25 |
+
temperature=temperature,
|
26 |
+
pad_token_id=tokenizer.eos_token_id
|
27 |
+
)
|
28 |
+
return tokenizer.decode(output[0], skip_special_tokens=True)
|
29 |
+
|
30 |
+
# Create the Gradio interface
|
31 |
+
iface = gr.Interface(
|
32 |
+
fn=generate_text,
|
33 |
+
inputs=[
|
34 |
+
gr.Textbox(label="Enter your prompt", placeholder="Start typing...", lines=5),
|
35 |
+
gr.Slider(minimum=50, maximum=200, value=100, step=1, label="Max Length"),
|
36 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.7, step=0.1, label="Temperature"),
|
37 |
+
],
|
38 |
+
outputs="text",
|
39 |
+
title="LLaMA 3.2 Text Generator",
|
40 |
+
description="Generate text using the LLaMA 3.2 model. Adjust the settings and input a prompt to generate responses.",
|
41 |
+
)
|
42 |
+
|
43 |
+
# Launch the Gradio app
|
44 |
+
iface.launch(share=True)
|