msaifee commited on
Commit
b6ed085
1 Parent(s): fec4095

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -26
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
- pipe = pipeline("text-generation", model=model_name, torch_dtype=torch.bfloat16, device_map="auto")
20
-
21
- pipe("How are you doing?")
22
-
23
- # # Define the inference function
24
- # def generate_text(prompt, max_length, temperature):
25
- # inputs = tokenizer(prompt, return_tensors="pt")
26
- # output = model.generate(inputs['input_ids'], max_length=max_length, temperature=temperature)
27
- # return tokenizer.decode(output[0], skip_special_tokens=True)
28
-
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..."),
35
- # gr.Slider(minimum=50, maximum=200, label="Max Length", value=100),
36
- # gr.Slider(minimum=0.1, maximum=1.0, label="Temperature", value=0.7),
37
- # ],
38
- # outputs="text",
39
- # title="LLaMA 3.2 Text Generator",
40
- # description="Enter a prompt to generate text using the LLaMA 3.2 model.",
41
- # )
42
-
43
- # # Launch the Gradio app
44
- # iface.launch()
 
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)