File size: 1,169 Bytes
a8cc6e3
7fdd3da
 
a8cc6e3
 
1a4cca4
 
7fdd3da
d7d02d9
7fdd3da
 
a8cc6e3
d7d02d9
1a4cca4
 
a8cc6e3
 
 
 
 
 
 
 
 
1a4cca4
7fdd3da
 
 
a8cc6e3
 
 
 
 
c612cee
 
a8cc6e3
 
b56227c
 
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
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
import spaces

zero = torch.Tensor([0]).cuda()

# Load model and tokenizer only once, outside the function
model_name = "deepapaikar/Katzbot_Llama_7b_QA_10eps"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name,  device_map='auto')



@spaces.GPU
def generate_text(input_text):
    """Generates text using the LlamaKatz-3x8B model.

    Args:
        input_text (str): The input text as a prompt.

    Returns:
        str: The generated text.
    """
    inputs = tokenizer(input_text, return_tensors="pt").to(zero.device)
    outputs = model.generate(**inputs)
    generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return generated_text

iface = gr.Interface(
    fn=generate_text,
    inputs=gr.Textbox(lines=5, label="Enter your text here:"),
    outputs=gr.Textbox(lines=5, label="Generated Text:"),
    title="KatzLLaMA",
    description="Enter some text and this app will generate more text based on it using the KatzLLaMA."
)

if __name__ == "__main__":
    iface.launch(debug=True)