File size: 1,068 Bytes
f9a388b
 
bce1941
f9a388b
bce1941
f9a388b
98c19b4
bce1941
 
 
 
 
 
 
98c19b4
 
bce1941
 
98c19b4
f9a388b
bce1941
 
f9a388b
bce1941
f9a388b
 
bce1941
f9a388b
 
bce1941
f9a388b
 
bce1941
f9a388b
 
bce1941
f9a388b
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
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
from accelerate import infer_auto_device_map

# Load the model name
model_name = "ai4bharat/Airavata"

# Load the tokenizer
tokenizer = AutoTokenizer.from_pretrained(model_name)

# Automatically determine the device map
device_map = infer_auto_device_map(model_name)

# Load the model with the device map
model = AutoModelForCausalLM.from_pretrained(
    model_name, 
    device_map=device_map, 
    load_in_8bit=True  # Use 8-bit precision for reduced memory usage
)

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

# Create the Gradio interface
interface = gr.Interface(
    fn=generate_text,
    inputs="text",
    outputs="text",
    title="Airavata Text Generation Model",
    description="This is the AI4Bharat Airavata model for text generation in Indic languages."
)

# Launch the interface
interface.launch()