Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import spaces
|
3 |
+
from unsloth import FastLanguageModel
|
4 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
5 |
+
model_name = "VanguardAI/BhashiniLLaMa3-8B_LoRA_Adapters",
|
6 |
+
max_seq_length = 2048,
|
7 |
+
dtype = None,
|
8 |
+
load_in_4bit = True,)
|
9 |
+
FastLanguageModel.for_inference(model)
|
10 |
+
|
11 |
+
|
12 |
+
condition= '''
|
13 |
+
ALWAYS provide output in a JSON format.
|
14 |
+
'''
|
15 |
+
|
16 |
+
alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
|
17 |
+
|
18 |
+
### Instruction:
|
19 |
+
{}
|
20 |
+
|
21 |
+
### Input:
|
22 |
+
{}
|
23 |
+
|
24 |
+
### Response:
|
25 |
+
{}"""
|
26 |
+
|
27 |
+
|
28 |
+
@spaces.GPU(duration=300)
|
29 |
+
def chunk_it(inventory_list,user_input_text):
|
30 |
+
inputs = tokenizer(
|
31 |
+
[
|
32 |
+
alpaca_prompt.format(
|
33 |
+
'''
|
34 |
+
You will receive text input that you need to analyze to perform the following tasks:
|
35 |
+
|
36 |
+
transaction: Record the details of an item transaction.
|
37 |
+
last n days transactions: Retrieve transaction records for a specified time period.
|
38 |
+
view risk inventory: View inventory items based on a risk category.
|
39 |
+
view inventory: View inventory details.
|
40 |
+
new items: Add new items to the inventory.
|
41 |
+
report generation: Generate various inventory reports.
|
42 |
+
delete item: Delete an existing Item.
|
43 |
+
|
44 |
+
Required Parameters:
|
45 |
+
Each task requires specific parameters to execute correctly:
|
46 |
+
|
47 |
+
transaction:
|
48 |
+
ItemName (string)
|
49 |
+
ItemQt (quantity - integer)
|
50 |
+
Type (string: "sale" or "purchase" or "return")
|
51 |
+
ReorderPoint (integer)
|
52 |
+
last n days transactions:
|
53 |
+
ItemName (string)
|
54 |
+
Duration (integer: number of days, if user input is in weeks, months or years then convert to days)
|
55 |
+
view risk inventory:
|
56 |
+
RiskType (string: "overstock", "understock", or "Null" for all risk types)
|
57 |
+
view inventory:
|
58 |
+
ItemName (string)
|
59 |
+
new items:
|
60 |
+
ItemName (string)
|
61 |
+
SellingPrice (number)
|
62 |
+
CostPrice (number)
|
63 |
+
report generation:
|
64 |
+
ItemName (string)
|
65 |
+
Duration (integer: number of days, if user input is in weeks, months or years then convert to days )
|
66 |
+
ReportType (string: "profit", "revenue", "inventory", or "Null" for all reports)
|
67 |
+
|
68 |
+
The ItemName must always be matched from the below list of names, EXCEPT for when the Function is "new items".
|
69 |
+
'''+ inventory_list +
|
70 |
+
'''
|
71 |
+
ALWAYS provide output in a JSON format.
|
72 |
+
''', # instruction
|
73 |
+
user_input_text, # input
|
74 |
+
"", # output - leave this blank for generation!
|
75 |
+
)
|
76 |
+
], return_tensors = "pt").to("cuda")
|
77 |
+
outputs = model.generate(**inputs, max_new_tokens = 216, use_cache = True)
|
78 |
+
content= tokenizer.batch_decode(outputs)
|
79 |
+
return content
|
80 |
+
|
81 |
+
|
82 |
+
iface=gr.Interface(fn=chunk_it,
|
83 |
+
inputs="text",
|
84 |
+
outputs="text",
|
85 |
+
title="Bhashini_LLaMa_LoRA",
|
86 |
+
)
|
87 |
+
iface = gr.Interface(
|
88 |
+
fn=chunk_it,
|
89 |
+
inputs=[
|
90 |
+
gr.Textbox(label="user_input_text", lines=3),
|
91 |
+
gr.Textbox(label="inventory_list", lines=3)
|
92 |
+
],
|
93 |
+
outputs="text",
|
94 |
+
title="SomeModel",
|
95 |
+
)
|
96 |
+
iface.launch(inline=False)
|