CE5.0_expert / app.py
mherrador's picture
Create app.py
010715e verified
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
# Load your model and tokenizer WITHOUT 4-bit quantization
model_name = "mherrador/CE5.0_expert"
device = torch.device("cpu")
model = AutoModelForCausalLM.from_pretrained(
model_name,
# No quantization_config here
trust_remote_code=True,
).to(device)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# Function to generate recommendations
def generate_recommendations(input_text):
inputs = tokenizer(input_text, return_tensors="pt").to(device) # Move input to device
outputs = model.generate(**inputs, max_new_tokens=128)
recommendations = tokenizer.batch_decode(outputs)[0]
return recommendations
# Create the Gradio interface
iface = gr.Interface(
fn=generate_recommendations,
inputs=gr.Textbox(lines=5, placeholder="Enter your questions here..."),
outputs=gr.Textbox(lines=10),
title="Circular Economy Recommender",
description="Enter your questions about circular economy practices to get recommendations.",
)
# Launch the interface
iface.launch()