Initial Space setup
Browse files
app.py
CHANGED
@@ -1,27 +1,38 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import pipeline
|
|
|
3 |
|
4 |
-
# Load
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
chatbot = pipeline(
|
6 |
"text2text-generation",
|
7 |
-
model=
|
8 |
-
tokenizer=
|
|
|
9 |
)
|
10 |
|
11 |
def respond(query):
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
19 |
return out
|
20 |
|
21 |
-
# Build Gradio interface sss
|
22 |
with gr.Blocks() as demo:
|
23 |
gr.Markdown("# 🤖 Bayedger FAQ Chatbot")
|
24 |
-
txt = gr.Textbox(label="Ask me anything"
|
25 |
out = gr.Textbox(label="Answer")
|
26 |
txt.submit(respond, txt, out)
|
27 |
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
3 |
+
from peft import PeftModel
|
4 |
|
5 |
+
# 1) Load the original base model & tokenizer
|
6 |
+
BASE_MODEL = "facebook/blenderbot-400M-distill"
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
|
8 |
+
base_model = AutoModelForSeq2SeqLM.from_pretrained(BASE_MODEL)
|
9 |
+
|
10 |
+
# 2) Load your fine-tuned LoRA adapter on top
|
11 |
+
ADAPTER_REPO = "abinashnp/bayedger-chatbot"
|
12 |
+
model = PeftModel.from_pretrained(base_model, ADAPTER_REPO)
|
13 |
+
|
14 |
+
# 3) Wrap that in a text2text pipeline
|
15 |
chatbot = pipeline(
|
16 |
"text2text-generation",
|
17 |
+
model=model,
|
18 |
+
tokenizer=tokenizer,
|
19 |
+
device_map="auto", # leave out device arg when using accelerate device_map
|
20 |
)
|
21 |
|
22 |
def respond(query):
|
23 |
+
out = chatbot(
|
24 |
+
f"question: {query} answer:",
|
25 |
+
max_new_tokens=150,
|
26 |
+
temperature=1.0,
|
27 |
+
top_p=0.9,
|
28 |
+
repetition_penalty=1.1,
|
29 |
+
num_beams=1
|
30 |
+
)[0]["generated_text"]
|
31 |
return out
|
32 |
|
|
|
33 |
with gr.Blocks() as demo:
|
34 |
gr.Markdown("# 🤖 Bayedger FAQ Chatbot")
|
35 |
+
txt = gr.Textbox(label="Ask me anything")
|
36 |
out = gr.Textbox(label="Answer")
|
37 |
txt.submit(respond, txt, out)
|
38 |
|