EduMentor / app.py
shubhayansarkar's picture
Update app.py
22f6c65 verified
import gradio as gr
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
# Load the fine-tuned quantized model and tokenizer
model = AutoModelForCausalLM.from_pretrained(
"pitangent-ds/academic_phy",
load_in_8bit=True, # Quantized model
device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained("pitangent-ds/academic_phy")
# Function for inference
def generate_response(input_text):
inputs = tokenizer(input_text, return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=50)
decoded_output = tokenizer.decode(outputs[0], skip_special_tokens=True)
return decoded_output
# Gradio Interface
interface = gr.Interface(
fn=generate_response,
inputs=gr.Textbox(label="Enter input text:"),
outputs=gr.Textbox(label="Generated Output"),
title="Quantized Language Model",
description="A Hugging Face Space deployment of a fine-tuned, 8-bit quantized language model."
)
# Launch the app
if __name__ == "__main__":
interface.launch()