Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,16 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM,
|
4 |
|
5 |
# Model ID
|
6 |
model_id = "large-traversaal/Alif-1.0-8B-Instruct"
|
7 |
|
8 |
-
#
|
9 |
-
quantization_config = BitsAndBytesConfig(
|
10 |
-
load_in_4bit=True,
|
11 |
-
bnb_4bit_compute_dtype=torch.float16,
|
12 |
-
bnb_4bit_use_double_quant=True,
|
13 |
-
bnb_4bit_quant_type="nf4"
|
14 |
-
)
|
15 |
-
|
16 |
-
# Load tokenizer and model in 4-bit
|
17 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
18 |
-
model = AutoModelForCausalLM.from_pretrained(
|
19 |
-
model_id,
|
20 |
-
quantization_config=quantization_config,
|
21 |
-
device_map="auto"
|
22 |
-
)
|
23 |
|
24 |
# Create text generation pipeline
|
25 |
-
chatbot = pipeline("text-generation", model=model, tokenizer=tokenizer,
|
26 |
|
27 |
# Function to generate responses
|
28 |
def chat(message):
|
@@ -32,12 +20,9 @@ def chat(message):
|
|
32 |
# Gradio UI
|
33 |
with gr.Blocks() as demo:
|
34 |
gr.Markdown("# π€ Alif Chatbot - Urdu Language AI Model")
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
submit_btn = gr.Button("Send")
|
39 |
-
with gr.Row():
|
40 |
-
bot_response = gr.Textbox(label="AI Response")
|
41 |
|
42 |
submit_btn.click(fn=chat, inputs=user_input, outputs=bot_response)
|
43 |
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
4 |
|
5 |
# Model ID
|
6 |
model_id = "large-traversaal/Alif-1.0-8B-Instruct"
|
7 |
|
8 |
+
# Load tokenizer and model (CPU-friendly)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
10 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="cpu") # Changed to CPU
|
|
|
|
|
|
|
|
|
11 |
|
12 |
# Create text generation pipeline
|
13 |
+
chatbot = pipeline("text-generation", model=model, tokenizer=tokenizer, device="cpu") # Ensuring CPU use
|
14 |
|
15 |
# Function to generate responses
|
16 |
def chat(message):
|
|
|
20 |
# Gradio UI
|
21 |
with gr.Blocks() as demo:
|
22 |
gr.Markdown("# π€ Alif Chatbot - Urdu Language AI Model")
|
23 |
+
user_input = gr.Textbox(label="User Input", placeholder="Ψ§ΩΎΩΨ§ Ψ³ΩΨ§Ω ΫΫΨ§ΪΊ ΩΪ©ΪΎΫΪΊ...")
|
24 |
+
submit_btn = gr.Button("Send")
|
25 |
+
bot_response = gr.Textbox(label="AI Response")
|
|
|
|
|
|
|
26 |
|
27 |
submit_btn.click(fn=chat, inputs=user_input, outputs=bot_response)
|
28 |
|