mherrador commited on
Commit
a2fd72f
·
verified ·
1 Parent(s): efcef06

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +39 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
3
+ import torch
4
+
5
+ # Load your model and tokenizer using the adapter weights
6
+ model_name = "mherrador/CE-5.0" # Replace with your actual model name
7
+ bnb_config = BitsAndBytesConfig(
8
+ load_in_4bit=True,
9
+ bnb_4bit_use_double_quant=True,
10
+ bnb_4bit_quant_type="nf4",
11
+ bnb_4bit_compute_dtype=torch.bfloat16,
12
+ )
13
+
14
+ model = AutoModelForCausalLM.from_pretrained(
15
+ model_name,
16
+ quantization_config=bnb_config,
17
+ device_map="auto",
18
+ trust_remote_code=True,
19
+ )
20
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
21
+
22
+ # Function to generate recommendations
23
+ def generate_recommendations(input_text):
24
+ inputs = tokenizer(input_text, return_tensors="pt").to("cuda")
25
+ outputs = model.generate(**inputs, max_new_tokens=128)
26
+ recommendations = tokenizer.batch_decode(outputs)[0]
27
+ return recommendations
28
+
29
+ # Create the Gradio interface
30
+ iface = gr.Interface(
31
+ fn=generate_recommendations,
32
+ inputs=gr.Textbox(lines=5, placeholder="Enter your questions here..."),
33
+ outputs=gr.Textbox(lines=10),
34
+ title="Circular Economy Recommender",
35
+ description="Enter your questions about circular economy practices to get recommendations.",
36
+ )
37
+
38
+ # Launch the interface
39
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ unsloth
3
+ torch