File size: 1,019 Bytes
9152d2f
41ebf03
 
 
 
 
22f6c65
41ebf03
 
 
22f6c65
41ebf03
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9152d2f
 
41ebf03
9152d2f
41ebf03
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
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()