File size: 3,405 Bytes
3a16188
f823e77
 
0e665e7
18aeeba
 
fe1b079
494f37f
 
fe1b079
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3a16188
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import re
import spaces
import gradio as gr
from peft import PeftModel, PeftConfig
from peft import AutoPeftModelForCausalLM
from transformers import AutoTokenizer
model = AutoPeftModelForCausalLM.from_pretrained(
        "FlawedLLM/BhashiniLLM", # YOUR MODEL YOU USED FOR TRAINING
        load_in_4bit = True,
)
tokenizer = AutoTokenizer.from_pretrained("FlawedLLM/BhashiniLLM")
@spaces.GPU(duration=300)
def chunk_it(input_command):

    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.
    
    ### Instruction:
    {}
    
    ### Input:
    {}
    
    ### Response:
    {}"""
    inputs = tokenizer(
    [
        alpaca_prompt.format(
            '''
            You will receive  text input that you need to analyze to perform the following tasks:
    
            transaction: Record the details of an item transaction.
            last n days transactions: Retrieve transaction records for a specified time period.
            view risk inventory: View inventory items based on a risk category.
            view inventory: View inventory details.
            new items: Add new items to the inventory.
            old items: View old items in inventory.
            report generation: Generate various inventory reports.
            Required Parameters:
    
            Each task requires specific parameters to execute correctly:
    
            transaction:
                ItemName (string)
                ItemQt (quantity - integer)
                Flow (string: "in" or "out")
                ShelfNo (string or integer)
            last n days transactions:
                ItemName (string)
                Duration (integer: number of days, default: 30)
            view risk inventory:
                RiskType (string: "overstock", "understock", or Null for all risk types)
            view inventory:
                ItemName (string)
                ShelfNo (string or integer)
            new items:
                ItemName (string)
                SellingPrice (number)
                CostPrice (number)
            old items:
                ShelfNo (string or integer)
            report generation:
                ItemName (string)
                Duration (integer: number of days, default: 6)
                ReportType (string: "profit", "revenue", "inventory", or Null for all reports)
    
            ALWAYS provide output in a JSON format.''', # instruction
            input_command, # input
            "", # output - leave this blank for generation!
        )
    ], return_tensors = "pt").to("cuda")
    
    outputs = model.generate(**inputs, max_new_tokens = 216, use_cache = True)
    tokenizer.batch_decode(outputs)
    
    reply=tokenizer.batch_decode(outputs)
    # Regular expression pattern to match content between "### Response:" and "<|end_of_text|>"
    pattern = r"### Response:\n(.*?)<\|end_of_text\|>"
    # Search for the pattern in the text
    match = re.search(pattern, reply[0], re.DOTALL)  # re.DOTALL allows '.' to match newlines
    reply = match.group(1).strip()  # Extract and remove extra whitespace

    return reply


iface=gr.Interface(fn=chunk_it,
                  inputs="text",
                  outputs="text",
                  title="Formatter_Pro",
                  )
iface.launch(inline=False)