FlawedLLM
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,82 @@
|
|
| 1 |
-
import
|
|
|
|
| 2 |
|
| 3 |
-
def greet(name):
|
| 4 |
-
return "Hello " + name + "!!"
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
from unsloth import FastLanguageModel
|
| 3 |
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
if True:
|
| 6 |
+
from unsloth import FastLanguageModel
|
| 7 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
| 8 |
+
model_name = "FlawedLLM/BhashiniLLM", # YOUR MODEL YOU USED FOR TRAINING
|
| 9 |
+
max_seq_length = max_seq_length,
|
| 10 |
+
dtype = dtype,
|
| 11 |
+
load_in_4bit = load_in_4bit,
|
| 12 |
+
)
|
| 13 |
+
FastLanguageModel.for_inference(model) # Enable native 2x faster inference
|
| 14 |
+
|
| 15 |
+
@spaces.GPU
|
| 16 |
+
def chunk_it(input_command):
|
| 17 |
+
inputs = tokenizer(
|
| 18 |
+
[
|
| 19 |
+
alpaca_prompt.format(
|
| 20 |
+
'''
|
| 21 |
+
You will receive text input that you need to analyze to perform the following tasks:
|
| 22 |
+
|
| 23 |
+
transaction: Record the details of an item transaction.
|
| 24 |
+
last n days transactions: Retrieve transaction records for a specified time period.
|
| 25 |
+
view risk inventory: View inventory items based on a risk category.
|
| 26 |
+
view inventory: View inventory details.
|
| 27 |
+
new items: Add new items to the inventory.
|
| 28 |
+
old items: View old items in inventory.
|
| 29 |
+
report generation: Generate various inventory reports.
|
| 30 |
+
Required Parameters:
|
| 31 |
+
|
| 32 |
+
Each task requires specific parameters to execute correctly:
|
| 33 |
+
|
| 34 |
+
transaction:
|
| 35 |
+
ItemName (string)
|
| 36 |
+
ItemQt (quantity - integer)
|
| 37 |
+
Flow (string: "in" or "out")
|
| 38 |
+
ShelfNo (string or integer)
|
| 39 |
+
last n days transactions:
|
| 40 |
+
ItemName (string)
|
| 41 |
+
Duration (integer: number of days, default: 30)
|
| 42 |
+
view risk inventory:
|
| 43 |
+
RiskType (string: "overstock", "understock", or Null for all risk types)
|
| 44 |
+
view inventory:
|
| 45 |
+
ItemName (string)
|
| 46 |
+
ShelfNo (string or integer)
|
| 47 |
+
new items:
|
| 48 |
+
ItemName (string)
|
| 49 |
+
SellingPrice (number)
|
| 50 |
+
CostPrice (number)
|
| 51 |
+
old items:
|
| 52 |
+
ShelfNo (string or integer)
|
| 53 |
+
report generation:
|
| 54 |
+
ItemName (string)
|
| 55 |
+
Duration (integer: number of days, default: 6)
|
| 56 |
+
ReportType (string: "profit", "revenue", "inventory", or Null for all reports)
|
| 57 |
+
|
| 58 |
+
ALWAYS provide output in a JSON format.''', # instruction
|
| 59 |
+
input_command, # input
|
| 60 |
+
"", # output - leave this blank for generation!
|
| 61 |
+
)
|
| 62 |
+
], return_tensors = "pt").to("cuda")
|
| 63 |
+
|
| 64 |
+
outputs = model.generate(**inputs, max_new_tokens = 216, use_cache = True)
|
| 65 |
+
tokenizer.batch_decode(outputs)
|
| 66 |
+
|
| 67 |
+
reply=tokenizer.batch_decode(outputs)
|
| 68 |
+
# Regular expression pattern to match content between "### Response:" and "<|end_of_text|>"
|
| 69 |
+
pattern = r"### Response:\n(.*?)<\|end_of_text\|>"
|
| 70 |
+
# Search for the pattern in the text
|
| 71 |
+
match = re.search(pattern, reply[0], re.DOTALL) # re.DOTALL allows '.' to match newlines
|
| 72 |
+
reply = match.group(1).strip() # Extract and remove extra whitespace
|
| 73 |
+
|
| 74 |
+
return reply
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
iface=gr.Interface(fn=chunk_it,
|
| 78 |
+
inputs="text",
|
| 79 |
+
outputs="text",
|
| 80 |
+
title="Formatter_Pro",
|
| 81 |
+
)
|
| 82 |
+
iface.launch(inline=False)
|