Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,20 +14,16 @@ user_name = "M. Galal"
|
|
| 14 |
VECTORSTORE_DIR = "./vectorstores"
|
| 15 |
os.makedirs(VECTORSTORE_DIR, exist_ok=True)
|
| 16 |
|
| 17 |
-
# Embeddings for RAG
|
| 18 |
embeddings = HuggingFaceEmbeddings(
|
| 19 |
model_name="sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2"
|
| 20 |
)
|
| 21 |
|
| 22 |
# Hugging Face Arabic model for generation
|
| 23 |
-
HF_MODEL = "aubmindlab/aragpt2-mega"
|
| 24 |
tokenizer = AutoTokenizer.from_pretrained(HF_MODEL, trust_remote_code=True)
|
| 25 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 26 |
-
|
| 27 |
-
)
|
| 28 |
-
generator = pipeline(
|
| 29 |
-
"text-generation", model=model, tokenizer=tokenizer, device=0
|
| 30 |
-
)
|
| 31 |
|
| 32 |
# Prompt template
|
| 33 |
prompt_template = """
|
|
@@ -92,7 +88,7 @@ def answer_question(file_key, question):
|
|
| 92 |
# 3️⃣ Gradio interface
|
| 93 |
# -----------------------------
|
| 94 |
def gradio_interface(file, question):
|
| 95 |
-
file_key = file.name.replace(".txt",
|
| 96 |
file_path = os.path.join(VECTORSTORE_DIR, file.name)
|
| 97 |
with open(file_path, "wb") as f:
|
| 98 |
f.write(file.read())
|
|
|
|
| 14 |
VECTORSTORE_DIR = "./vectorstores"
|
| 15 |
os.makedirs(VECTORSTORE_DIR, exist_ok=True)
|
| 16 |
|
| 17 |
+
# Embeddings for RAG
|
| 18 |
embeddings = HuggingFaceEmbeddings(
|
| 19 |
model_name="sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2"
|
| 20 |
)
|
| 21 |
|
| 22 |
# Hugging Face Arabic model for generation
|
| 23 |
+
HF_MODEL = "aubmindlab/aragpt2-mega"
|
| 24 |
tokenizer = AutoTokenizer.from_pretrained(HF_MODEL, trust_remote_code=True)
|
| 25 |
+
model = AutoModelForCausalLM.from_pretrained(HF_MODEL, torch_dtype=torch.float16, device_map="auto", trust_remote_code=True)
|
| 26 |
+
generator = pipeline("text-generation", model=model, tokenizer=tokenizer, device=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
# Prompt template
|
| 29 |
prompt_template = """
|
|
|
|
| 88 |
# 3️⃣ Gradio interface
|
| 89 |
# -----------------------------
|
| 90 |
def gradio_interface(file, question):
|
| 91 |
+
file_key = file.name.replace(".txt","")
|
| 92 |
file_path = os.path.join(VECTORSTORE_DIR, file.name)
|
| 93 |
with open(file_path, "wb") as f:
|
| 94 |
f.write(file.read())
|