File size: 1,516 Bytes
d4a9c54
1871f0d
d4a9c54
1871f0d
20ea8ef
 
1871f0d
d4a9c54
023ef9c
 
d4a9c54
023ef9c
 
d4a9c54
 
4ae60a7
 
023ef9c
fec4095
bf86fa8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import gradio as gr
from huggingface_hub import login
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
from transformers import pipeline

# Fetch API token from environment variable
api_token = os.getenv("Llama_Token")

# Authenticate with Hugging Face
login(api_token)

# Load LLaMA 3.2 model and tokenizer with the API token
model_name = "meta-llama/Llama-3.2-1B"
tokenizer = AutoTokenizer.from_pretrained(model_name, token=api_token)
model = AutoModelForCausalLM.from_pretrained(model_name, token=api_token)

pipe = pipeline("text-generation", model=model_name, torch_dtype=torch.bfloat16, device_map="auto")

pipe("How are you doing?")

# # Define the inference function
# def generate_text(prompt, max_length, temperature):
#     inputs = tokenizer(prompt, return_tensors="pt")
#     output = model.generate(inputs['input_ids'], max_length=max_length, temperature=temperature)
#     return tokenizer.decode(output[0], skip_special_tokens=True)


# # Create the Gradio interface
# iface = gr.Interface(
#     fn=generate_text,
#     inputs=[
#         gr.Textbox(label="Enter your prompt", placeholder="Start typing..."),
#         gr.Slider(minimum=50, maximum=200, label="Max Length", value=100),
#         gr.Slider(minimum=0.1, maximum=1.0, label="Temperature", value=0.7),
#     ],
#     outputs="text",
#     title="LLaMA 3.2 Text Generator",
#     description="Enter a prompt to generate text using the LLaMA 3.2 model.",
# )

# # Launch the Gradio app
# iface.launch()