File size: 1,311 Bytes
136e821
 
 
ba8ad86
136e821
 
1c670bf
 
 
 
 
 
 
 
 
 
136e821
 
ba8ad86
136e821
1c670bf
136e821
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
import spaces

# Load model and tokenizer

tokenizer = None
model = None

def loadmodel():
    global tokenizer, model
    tokenizer = AutoTokenizer.from_pretrained("ISTA-DASLab/Meta-Llama-3.1-70B-AQLM-PV-2Bit-1x16")
    model = AutoModelForCausalLM.from_pretrained("ISTA-DASLab/Meta-Llama-3.1-70B-AQLM-PV-2Bit-1x16", torch_dtype=torch.float16, device_map= 'auto')
    #model = model.to('cuda')  # Move the model to GPU if available
    pass

# Define a function for generating text from a prompt
@spaces.GPU
def generate_text(prompt):
    global tokenizer, model
    inputs = tokenizer(prompt, return_tensors="pt").to('cuda')  # Tokenize input and move to GPU
    outputs = model.generate(inputs.input_ids, max_length=100)  # Generate output text
    return tokenizer.decode(outputs[0], skip_special_tokens=True)  # Decode and return the text

# Create Gradio Interface
interface = gr.Interface(
    fn=generate_text,  # Function that handles text generation
    inputs="text",  # Input is a text box
    outputs="text",  # Output is a text box
    title="Meta-Llama-3.1-70B Text Generation",
    description="Enter a prompt and generate text using Meta-Llama-3.1-70B.",
)

# Launch the Gradio app
interface.launch()