Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# Load your model and tokenizer WITHOUT 4-bit quantization
|
6 |
+
model_name = "mherrador/CE5.0_expert"
|
7 |
+
device = torch.device("cpu")
|
8 |
+
|
9 |
+
model = AutoModelForCausalLM.from_pretrained(
|
10 |
+
model_name,
|
11 |
+
# No quantization_config here
|
12 |
+
trust_remote_code=True,
|
13 |
+
).to(device)
|
14 |
+
|
15 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
16 |
+
|
17 |
+
# Function to generate recommendations
|
18 |
+
def generate_recommendations(input_text):
|
19 |
+
inputs = tokenizer(input_text, return_tensors="pt").to(device) # Move input to device
|
20 |
+
outputs = model.generate(**inputs, max_new_tokens=128)
|
21 |
+
recommendations = tokenizer.batch_decode(outputs)[0]
|
22 |
+
return recommendations
|
23 |
+
|
24 |
+
# Create the Gradio interface
|
25 |
+
iface = gr.Interface(
|
26 |
+
fn=generate_recommendations,
|
27 |
+
inputs=gr.Textbox(lines=5, placeholder="Enter your questions here..."),
|
28 |
+
outputs=gr.Textbox(lines=10),
|
29 |
+
title="Circular Economy Recommender",
|
30 |
+
description="Enter your questions about circular economy practices to get recommendations.",
|
31 |
+
)
|
32 |
+
|
33 |
+
# Launch the interface
|
34 |
+
iface.launch()
|