Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -3,13 +3,20 @@ import spaces
|
|
3 |
import re
|
4 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
5 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
tokenizer = AutoTokenizer.from_pretrained("VanguardAI/BhashiniLLaMa3-8B_16bit_LoRA_Adapters")
|
8 |
-
model = AutoModelForCausalLM.from_pretrained("VanguardAI/BhashiniLLaMa3-8B_16bit_LoRA_Adapters")
|
9 |
|
10 |
-
condition = '''
|
11 |
-
ALWAYS provide output in a JSON format.
|
12 |
-
'''
|
13 |
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.
|
14 |
|
15 |
### Instruction:
|
@@ -21,6 +28,52 @@ alpaca_prompt = """Below is an instruction that describes a task, paired with an
|
|
21 |
### Response:
|
22 |
{}"""
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
@spaces.GPU()
|
26 |
def chunk_it(inventory_list, user_input_text):
|
@@ -28,43 +81,7 @@ def chunk_it(inventory_list, user_input_text):
|
|
28 |
inputs = tokenizer(
|
29 |
[
|
30 |
alpaca_prompt.format(
|
31 |
-
|
32 |
-
You will receive text input that you need to analyze to perform the following tasks:
|
33 |
-
|
34 |
-
transaction: Record the details of an item transaction.
|
35 |
-
last n days transactions: Retrieve transaction records for a specified time period.
|
36 |
-
view risk inventory: View inventory items based on a risk category.
|
37 |
-
view inventory: View inventory details.
|
38 |
-
new items: Add new items to the inventory.
|
39 |
-
report generation: Generate various inventory reports.
|
40 |
-
delete item: Delete an existing Item.
|
41 |
-
|
42 |
-
Required Parameters:
|
43 |
-
Each task requires specific parameters to execute correctly:
|
44 |
-
|
45 |
-
transaction:
|
46 |
-
ItemName (string)
|
47 |
-
ItemQt (quantity - integer)
|
48 |
-
Type (string: "sale" or "purchase" or "return")
|
49 |
-
ReorderPoint (integer)
|
50 |
-
last n days transactions:
|
51 |
-
ItemName (string)
|
52 |
-
Duration (integer: number of days, if user input is in weeks, months or years then convert to days)
|
53 |
-
view risk inventory:
|
54 |
-
RiskType (string: "overstock", "understock", or "Null" for all risk types)
|
55 |
-
view inventory:
|
56 |
-
ItemName (string)
|
57 |
-
new items:
|
58 |
-
ItemName (string)
|
59 |
-
SellingPrice (number)
|
60 |
-
CostPrice (number)
|
61 |
-
report generation:
|
62 |
-
ItemName (string)
|
63 |
-
Duration (integer: number of days, if user input is in weeks, months or years then convert to days)
|
64 |
-
ReportType (string: "profit", "revenue", "inventory", or "Null" for all reports)
|
65 |
-
|
66 |
-
The ItemName must always be matched from the below list of names, EXCEPT for when the Function is "new items".
|
67 |
-
''' + inventory_list + condition, # instruction
|
68 |
user_input_text, # input
|
69 |
"", # output - leave this blank for generation!
|
70 |
)
|
@@ -88,7 +105,7 @@ iface = gr.Interface(
|
|
88 |
gr.Textbox(label="inventory_list", lines=5)
|
89 |
],
|
90 |
outputs="text",
|
91 |
-
title="
|
92 |
)
|
93 |
|
94 |
iface.launch(inline=False)
|
|
|
3 |
import re
|
4 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
5 |
import gradio as gr
|
6 |
+
import os
|
7 |
+
READ_HF=os.environ["read_hf"]
|
8 |
+
|
9 |
+
from unsloth import FastLanguageModel
|
10 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
11 |
+
model_name = "VanguardAI/CoT_multi_llama_LoRA_4bit", # YOUR MODEL YOU USED FOR TRAINING
|
12 |
+
max_seq_length = 2048,
|
13 |
+
dtype = None,
|
14 |
+
load_in_4bit = True,
|
15 |
+
token= READ_HF
|
16 |
+
)
|
17 |
+
FastLanguageModel.for_inference(model) # Enable native 2x faster inference
|
18 |
|
|
|
|
|
19 |
|
|
|
|
|
|
|
20 |
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.
|
21 |
|
22 |
### Instruction:
|
|
|
28 |
### Response:
|
29 |
{}"""
|
30 |
|
31 |
+
string = '''
|
32 |
+
You are an AI assistant tasked with managing inventory based on user instructions. You must meticulously analyze each user request to determine the appropriate action and execute it with the correct parameters.
|
33 |
+
|
34 |
+
**Here's your step-by-step thought process:**
|
35 |
+
|
36 |
+
1. **Identify the Function:** Carefully examine the user's input to determine the primary function they want to perform. The available functions are:
|
37 |
+
- `transaction`: Record a new item transaction.
|
38 |
+
- `last n days transactions`: Retrieve transaction records within a specific timeframe.
|
39 |
+
- `view inventory`: View inventory details for a specific category and risk level.
|
40 |
+
- `generate report`: Generate an inventory report.
|
41 |
+
|
42 |
+
2. **Extract Parameters:** Once you've identified the function, carefully extract the necessary parameters from the user's input. Each function requires specific parameters:
|
43 |
+
|
44 |
+
**`transaction`:**
|
45 |
+
- `ItemName`: (string) **Must be an exact match from the provided Item List.**
|
46 |
+
- `ItemQt`: (integer) The quantity of the item.
|
47 |
+
- `Type`: (string) "sale", "purchase", or "return".
|
48 |
+
|
49 |
+
**`last n days transactions`:**
|
50 |
+
- `ItemCategory`: (string) **Must be from the provided Item Category List.**
|
51 |
+
- `Duration`: (integer) Number of days (convert weeks, months, years to days).
|
52 |
+
|
53 |
+
**`view inventory`:**
|
54 |
+
- `ItemCategory`: (string) **Must be from the provided Item Category List.**
|
55 |
+
- `RiskType`: (string) "overstock", "understock", or "Null" (if risk inventory is not asked), or "All" for both overstock and understock.
|
56 |
+
|
57 |
+
**`generate report`:**
|
58 |
+
- `ItemCategory`: (string) **Must be from the provided Item Category List.**
|
59 |
+
- `Duration`: (integer) Number of days (convert weeks, months, years to days).
|
60 |
+
- `ReportType`: (string): "profit", "revenue", "inventory", or "Null" (for all reports).
|
61 |
+
|
62 |
+
3. **Validate Inputs:** Before proceeding, validate the extracted parameters:
|
63 |
+
|
64 |
+
- **ItemName:** Ensure the `ItemName` is an exact match from the provided Item List.
|
65 |
+
- **ItemCategory:** Ensure the `ItemCategory` is from the provided Category List.
|
66 |
+
- **Data Types:** Verify that all parameters are of the correct data type (string or integer).
|
67 |
+
|
68 |
+
4. **Output in JSON:** Always format your response as a JSON object.
|
69 |
+
|
70 |
+
**Additional Notes:**
|
71 |
+
- Pay close attention to the case and spelling of function names and parameters.
|
72 |
+
|
73 |
+
Category List : ["Dairy & Eggs", "Beverages & Snacks", "Cleaning & Hygiene", "Grains & Staples", "Personal Care", "Other"]
|
74 |
+
|
75 |
+
'''
|
76 |
+
|
77 |
|
78 |
@spaces.GPU()
|
79 |
def chunk_it(inventory_list, user_input_text):
|
|
|
81 |
inputs = tokenizer(
|
82 |
[
|
83 |
alpaca_prompt.format(
|
84 |
+
string + inventory_list, # instruction
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
user_input_text, # input
|
86 |
"", # output - leave this blank for generation!
|
87 |
)
|
|
|
105 |
gr.Textbox(label="inventory_list", lines=5)
|
106 |
],
|
107 |
outputs="text",
|
108 |
+
title="Testing",
|
109 |
)
|
110 |
|
111 |
iface.launch(inline=False)
|