abinashnp commited on
Commit
c90040d
·
1 Parent(s): 7c893bd

Initial Space setup

Browse files
Files changed (1) hide show
  1. app.py +24 -13
app.py CHANGED
@@ -1,27 +1,38 @@
1
  import gradio as gr
2
- from transformers import pipeline
 
3
 
4
- # Load your fine-tuned model from the Hub
 
 
 
 
 
 
 
 
 
5
  chatbot = pipeline(
6
  "text2text-generation",
7
- model="abinashnp/bayedger-chatbot", # or your fine-tuned model ID
8
- tokenizer="abinashnp/bayedger-chatbot",
 
9
  )
10
 
11
  def respond(query):
12
- # generate response
13
- out = chatbot(f"question: {query} answer:",
14
- max_new_tokens=150,
15
- temperature=1.0,
16
- top_p=0.9,
17
- repetition_penalty=1.1,
18
- num_beams=1)[0]["generated_text"]
 
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", placeholder="Type your question here…")
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