Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,8 +8,6 @@ device = torch.device("cpu") # Ensure it's using CPU only
|
|
8 |
# Load model and tokenizer
|
9 |
model_name = "hosseinhimself/ISANG-v1.0-8B" # Replace with your model name
|
10 |
tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=False)
|
11 |
-
|
12 |
-
# Load the model for inference on CPU
|
13 |
model = AutoModelForCausalLM.from_pretrained(model_name).to(device)
|
14 |
|
15 |
# Define the Alpaca-style prompt template
|
@@ -24,23 +22,29 @@ You are ISANG, a multilingual large language model made by ISANG AI. You only re
|
|
24 |
### Response:
|
25 |
{}"""
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
# Define a function to generate responses
|
30 |
def generate_response(input_text, max_tokens=1024, temperature=0.7, history=[]):
|
31 |
-
#
|
32 |
-
|
|
|
|
|
|
|
|
|
33 |
|
34 |
-
# Tokenize the input
|
35 |
-
inputs = tokenizer(prompt, return_tensors="pt").to(device)
|
36 |
|
37 |
-
#
|
38 |
-
output = model.generate(
|
|
|
|
|
|
|
|
|
39 |
|
40 |
-
# Decode the model output
|
41 |
-
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
42 |
|
43 |
-
# Update
|
44 |
history.append(f"User: {input_text}")
|
45 |
history.append(f"AI: {response}")
|
46 |
|
@@ -59,7 +63,7 @@ iface = gr.Interface(
|
|
59 |
title="ISANG Chatbot",
|
60 |
description="A chatbot powered by ISANG-v1.0-8B model. Chat with me!",
|
61 |
theme="huggingface", # Purple theme
|
62 |
-
live=
|
63 |
)
|
64 |
|
65 |
# Launch the interface
|
|
|
8 |
# Load model and tokenizer
|
9 |
model_name = "hosseinhimself/ISANG-v1.0-8B" # Replace with your model name
|
10 |
tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=False)
|
|
|
|
|
11 |
model = AutoModelForCausalLM.from_pretrained(model_name).to(device)
|
12 |
|
13 |
# Define the Alpaca-style prompt template
|
|
|
22 |
### Response:
|
23 |
{}"""
|
24 |
|
25 |
+
# Function to generate responses
|
|
|
|
|
26 |
def generate_response(input_text, max_tokens=1024, temperature=0.7, history=[]):
|
27 |
+
# Retain only the last two exchanges for context
|
28 |
+
if len(history) > 2:
|
29 |
+
history = history[-2:]
|
30 |
+
|
31 |
+
# Format the prompt
|
32 |
+
prompt = "\n".join(history + [f"User: {input_text}\nAI:"])
|
33 |
|
34 |
+
# Tokenize the input
|
35 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(device)
|
36 |
|
37 |
+
# Generate model output
|
38 |
+
output = model.generate(
|
39 |
+
inputs.input_ids,
|
40 |
+
max_new_tokens=max_tokens,
|
41 |
+
temperature=temperature
|
42 |
+
)
|
43 |
|
44 |
+
# Decode the model output
|
45 |
+
response = tokenizer.decode(output[0], skip_special_tokens=True).strip()
|
46 |
|
47 |
+
# Update the history
|
48 |
history.append(f"User: {input_text}")
|
49 |
history.append(f"AI: {response}")
|
50 |
|
|
|
63 |
title="ISANG Chatbot",
|
64 |
description="A chatbot powered by ISANG-v1.0-8B model. Chat with me!",
|
65 |
theme="huggingface", # Purple theme
|
66 |
+
live=False # Set to False since live updates aren't required
|
67 |
)
|
68 |
|
69 |
# Launch the interface
|