File size: 1,646 Bytes
02a67dd
 
0240a50
02a67dd
 
 
 
0240a50
 
02a67dd
 
 
 
 
08cc45d
02a67dd
 
0240a50
02a67dd
08cc45d
 
0240a50
02a67dd
 
 
0240a50
02a67dd
 
0240a50
02a67dd
 
0240a50
02a67dd
 
 
0240a50
02a67dd
 
0240a50
02a67dd
 
 
 
0240a50
02a67dd
 
 
 
 
 
0240a50
02a67dd
0240a50
02a67dd
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: utf-8 -*-
"""app.ipynb

Automatically generated by Colab.

Original file is located at
    https://colab.research.google.com/drive/1qIFntwH-_zF7GkQbgjKoXMXnQpZ4HVse
"""

import gradio as gr
import streamlit as st
from transformers import AutoTokenizer,  AutoModelForSequenceClassification

# Load the base model
base_model_name = "bert-base-uncased"
tokenizer = AutoTokenizer.from_pretrained(base_model_name)
model =  AutoModelForSequenceClassification.from_pretrained(base_model_name)

# Load the adapter configuration and model files
adapter_config_path = "./config.json"
adapter_model_path = "./model.safetensors"

# Load the adapter into the model
adapter_name = "custom_adapter"  # Define your adapter name
model.load_adapter(adapter_config_path, model_file=adapter_model_path, load_as=adapter_name)

# Activate the adapter
model.set_active_adapters(adapter_name)

st.title("🤖 Chatbot with Adapter-Enhanced Model")
st.write("Interact with your custom adapter-enhanced model. Type a message and get responses!")

# Initialize or retrieve the chat history
if 'history' not in st.session_state:
    st.session_state['history'] = []

# Initialize Gradio
chatbot = Gradio(model=model, tokenizer=tokenizer)

# Define responses for greetings
@chatbot.on_event("welcome")
def welcome_handler(payload):
    return "Welcome! Type a message and get responses from the chatbot."

# Define responses for user messages
@chatbot.on_message
def message_handler(payload):
    user_input = payload["message"]
    response = chatbot.generate_response(user_input)
    return response

# Run Gradio
if __name__ == "__main__":
    chatbot.run()