File size: 1,222 Bytes
8ea78b5
95a9784
 
7b5c698
95a9784
1a19ed8
95a9784
7b5c698
 
030af36
6322140
7b5c698
8ea78b5
 
 
 
 
 
 
7b5c698
 
 
 
 
95a9784
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
from huggingface_hub import login




# Authenticate with the access token

login("HF_ACCESS_TOKEN", add_to_git_credential=True) 

# Retrieve token securely
token = os.getenv("HF_ACCESS_TOKEN")
if token is None:
    raise ValueError("HF_ACCESS_TOKEN not found. Did you set it in the Secrets?")
login(token)


model_name = "ayeshaNoor1/Llama_finetunedModel-1b"
tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=True)
model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=True)


# Define the text generation function
def generate_text(prompt):
    inputs = tokenizer(prompt, return_tensors="pt")
    outputs = model.generate(inputs.input_ids, max_length=100, num_return_sequences=1)
    response = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return response

# Create a Gradio interface
interface = gr.Interface(
    fn=generate_text,
    inputs="text",
    outputs="text",
    title="Fine-Tuned Llama 3.2 Generator",
    description="Enter a prompt to generate text using the fine-tuned Llama model.",
)

# Launch the Gradio app
if __name__ == "__main__":
    interface.launch()