msaifee commited on
Commit
1871f0d
1 Parent(s): b717c25

LlaMA3.2 testing interface with Gradio

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+
4
+ # Load LLaMA 3.2 model and tokenizer
5
+ model_name = "meta-llama/LLaMA-3.2" # Replace this with the correct model ID if necessary
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForCausalLM.from_pretrained(model_name)
8
+
9
+ # Define the inference function
10
+ def generate_text(prompt, max_length=100, temperature=0.7):
11
+ inputs = tokenizer(prompt, return_tensors="pt")
12
+ output = model.generate(inputs['input_ids'], max_length=max_length, temperature=temperature)
13
+ return tokenizer.decode(output[0], skip_special_tokens=True)
14
+
15
+ # Create the Gradio interface
16
+ iface = gr.Interface(
17
+ fn=generate_text,
18
+ inputs=[
19
+ gr.inputs.Textbox(label="Enter your prompt", placeholder="Start typing..."),
20
+ gr.inputs.Slider(minimum=50, maximum=200, default=100, label="Max Length"),
21
+ gr.inputs.Slider(minimum=0.1, maximum=1.0, default=0.7, label="Temperature"),
22
+ ],
23
+ outputs="text",
24
+ title="LLaMA 3.2 Text Generator",
25
+ description="Enter a prompt to generate text using the LLaMA 3.2 model.",
26
+ theme="compact",
27
+ )
28
+
29
+ # Launch the Gradio app
30
+ iface.launch()