Spaces:
Runtime error
Runtime error
File size: 1,029 Bytes
f9a388b bce1941 f9a388b bce1941 f9a388b 98c19b4 bce1941 b0ea0b7 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 |
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)
# Load the model first
model = AutoModelForCausalLM.from_pretrained(model_name, load_in_8bit=True)
# Now infer the device map
device_map = infer_auto_device_map(model)
# Move model to the appropriate device based on device_map
model.to(device_map)
# 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()
|