| | import subprocess |
| |
|
| | def uninstall_and_reinstall_bitsandbytes(): |
| | try: |
| | |
| | subprocess.run(["pip", "uninstall", "-y", "bitsandbytes"], check=True) |
| | print("Uninstalled bitsandbytes successfully.") |
| |
|
| | |
| | subprocess.run(["pip", "install", "-i", "https://pypi.org/simple/", "bitsandbytes"], check=True) |
| | print("Reinstalled bitsandbytes successfully.") |
| | except subprocess.CalledProcessError as e: |
| | print(f"Error during uninstallation or reinstallation: {e}") |
| |
|
| | |
| | uninstall_and_reinstall_bitsandbytes() |
| |
|
| | import os |
| | HF_TOKEN = os.environ["HF_TOKEN"] |
| | |
| | import re |
| | import spaces |
| | import gradio as gr |
| | import torch |
| | print(f"Is CUDA available: {torch.cuda.is_available()}") |
| | |
| | print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}") |
| | |
| | from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig |
| | from huggingface_hub import login, HfFolder |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | tokenizer = AutoTokenizer.from_pretrained("FlawedLLM/Bhashini_gemma_merged4bit_clean_final") |
| | model = AutoModelForCausalLM.from_pretrained("FlawedLLM/Bhashini_gemma_merged4bit_clean_final", |
| | device_map="auto",) |
| | |
| | |
| | @spaces.GPU(duration=300) |
| | def chunk_it(input_command, item_list): |
| | 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: |
| | {}""" |
| | if item_list is not None: |
| | item_list = f'''The ItemName should be chosen from the given list : {item_list} , except when adding item. If ItemName does not find anything SIMILAR in the list, then the ItemName should be "Null" ''' |
| | inputs = tokenizer( |
| | [ |
| | alpaca_prompt.format( |
| | f''' |
| | 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) |
| | Type (string: "sale" or "purchase" or "return") |
| | ShelfNo (string or integer) |
| | ReorderPoint (integer) |
| | last n days transactions: |
| | ItemName (string) |
| | Duration (integer: number of days) |
| | 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) |
| | ReportType (string: "profit", "revenue", "inventory", or Null for all reports) |
| | |
| | {item_list} |
| | |
| | |
| | ALWAYS provide output in a JSON format.''', |
| | input_command, |
| | "", |
| | ) |
| | ], 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) |
| | |
| | pattern = r"### Response:\n(.*?)<eos>" |
| | |
| | match = re.search(pattern, reply[0], re.DOTALL) |
| | reply = match.group(1).strip() |
| |
|
| | return reply |
| |
|
| |
|
| |
|
| | iface = gr.Interface( |
| | fn=chunk_it, |
| | inputs=[ |
| | gr.Textbox(label="Input Command", lines=3), |
| | gr.Textbox(label="Item List", lines=5) |
| | ], |
| | outputs="text", |
| | title="Formatter Pro", |
| | ) |
| |
|
| | iface.launch(inline=False) |