GIGAParviz commited on
Commit
e86a380
·
verified ·
1 Parent(s): 4b4114f

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -53
app.py DELETED
@@ -1,53 +0,0 @@
1
- import gradio as gr
2
- from unsloth import FastLanguageModel
3
- from transformers import BitsAndBytesConfig
4
- import torch
5
-
6
- # Model configuration
7
- model_name = "unsloth/llama-3-8b-bnb-4bit"
8
- max_seq_length = 512
9
- dtype = None
10
- load_in_4bit = True
11
-
12
- # Load model and tokenizer
13
- model, tokenizer = FastLanguageModel.from_pretrained(
14
- model_name=model_name,
15
- max_seq_length=2048,
16
- dtype=None,
17
- device_map="cpu",
18
- load_in_4bit=True,
19
- )
20
-
21
- device = torch.device('cpu')
22
- model = FastLanguageModel().to(device)
23
- FastLanguageModel.for_inference(model)
24
-
25
- # Define Alpaca prompt format
26
- alpaca_prompt = """
27
- ### Instruction:
28
- {0}
29
- ### Input:
30
- {1}
31
- ### Response:
32
- {2}
33
- """
34
-
35
- # Function to generate response
36
- def generate_response(user_input):
37
- prompt = alpaca_prompt.format(user_input, "", "")
38
- inputs = tokenizer([prompt], return_tensors="pt").to("cpu")
39
- outputs = model.generate(**inputs, max_new_tokens=64, use_cache=True)
40
- response = tokenizer.batch_decode(outputs, skip_special_tokens=True)
41
- return response[0]
42
-
43
- # Gradio interface
44
- iface = gr.Interface(
45
- fn=generate_response,
46
- inputs=gr.inputs.Textbox(lines=2, placeholder="یه چیزی بپرس...", label="Input"),
47
- outputs=gr.outputs.Textbox(label="Response"),
48
- title="Parviz Chat Bot",
49
- description="Ask a question in Persian or English."
50
- )
51
-
52
- # Launch the interface
53
- iface.launch()