Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,18 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from ctransformers import AutoModelForCausalLM
|
| 3 |
-
from huggingface_hub import hf_hub_download
|
| 4 |
-
import os
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
model_path = hf_hub_download(
|
| 8 |
-
repo_id="TheBloke/Mistral-7B-Instruct-v0.1-GGUF",
|
| 9 |
-
filename="mistral-7b-instruct-v0.1.Q4_K_M.gguf",
|
| 10 |
-
cache_dir="./"
|
| 11 |
-
)
|
| 12 |
-
|
| 13 |
-
# Load model directly from downloaded file
|
| 14 |
model = AutoModelForCausalLM.from_pretrained(
|
| 15 |
-
|
| 16 |
-
|
|
|
|
| 17 |
max_new_tokens=2048,
|
| 18 |
temperature=0.9,
|
| 19 |
repetition_penalty=1.1,
|
| 20 |
top_p=0.95
|
| 21 |
)
|
| 22 |
|
| 23 |
-
#
|
| 24 |
def generate_qa(text):
|
| 25 |
prompt = f"""### Instruction:
|
| 26 |
Based on the following SAP Note, generate exactly 20 unique and informative question-answer pairs.
|
|
@@ -30,16 +22,15 @@ Each question must refer to the SAP note number from text if additional context
|
|
| 30 |
{text}
|
| 31 |
|
| 32 |
### Response:"""
|
| 33 |
-
|
| 34 |
-
return response.strip()
|
| 35 |
|
| 36 |
-
# Gradio
|
| 37 |
demo = gr.Interface(
|
| 38 |
fn=generate_qa,
|
| 39 |
inputs=gr.Textbox(lines=20, label="SAP Note Text"),
|
| 40 |
outputs=gr.Textbox(lines=30, label="Generated Q&A Pairs"),
|
| 41 |
-
title="SAP Note Q&A Generator (Mistral GGUF
|
| 42 |
-
description="Paste SAP Note content to generate 20 Q&A pairs using Mistral 7B
|
| 43 |
)
|
| 44 |
|
| 45 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from ctransformers import AutoModelForCausalLM
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
# Load GGUF model directly from Hugging Face (no need to pre-download)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
model = AutoModelForCausalLM.from_pretrained(
|
| 6 |
+
"TheBloke/Mistral-7B-Instruct-v0.1-GGUF", # repo_id
|
| 7 |
+
model_file="mistral-7b-instruct-v0.1.Q4_K_M.gguf", # exact filename
|
| 8 |
+
model_type="mistral", # required
|
| 9 |
max_new_tokens=2048,
|
| 10 |
temperature=0.9,
|
| 11 |
repetition_penalty=1.1,
|
| 12 |
top_p=0.95
|
| 13 |
)
|
| 14 |
|
| 15 |
+
# Define the Q&A generation function
|
| 16 |
def generate_qa(text):
|
| 17 |
prompt = f"""### Instruction:
|
| 18 |
Based on the following SAP Note, generate exactly 20 unique and informative question-answer pairs.
|
|
|
|
| 22 |
{text}
|
| 23 |
|
| 24 |
### Response:"""
|
| 25 |
+
return model(prompt).strip()
|
|
|
|
| 26 |
|
| 27 |
+
# Create Gradio UI
|
| 28 |
demo = gr.Interface(
|
| 29 |
fn=generate_qa,
|
| 30 |
inputs=gr.Textbox(lines=20, label="SAP Note Text"),
|
| 31 |
outputs=gr.Textbox(lines=30, label="Generated Q&A Pairs"),
|
| 32 |
+
title="SAP Note Q&A Generator (Mistral GGUF - CPU)",
|
| 33 |
+
description="Paste SAP Note content to generate 20 Q&A pairs using Mistral 7B (Quantized GGUF model)"
|
| 34 |
)
|
| 35 |
|
| 36 |
if __name__ == "__main__":
|