Delete app.py
Browse files
app.py
DELETED
|
@@ -1,60 +0,0 @@
|
|
| 1 |
-
# -*- coding: utf-8 -*-
|
| 2 |
-
"""app.ipynb
|
| 3 |
-
|
| 4 |
-
Automatically generated by Colab.
|
| 5 |
-
|
| 6 |
-
Original file is located at
|
| 7 |
-
https://colab.research.google.com/drive/1qIFntwH-_zF7GkQbgjKoXMXnQpZ4HVse
|
| 8 |
-
"""
|
| 9 |
-
|
| 10 |
-
!pip install gradio
|
| 11 |
-
!pip install streamlit
|
| 12 |
-
|
| 13 |
-
!pip install transformers
|
| 14 |
-
|
| 15 |
-
import gradio as gr
|
| 16 |
-
import streamlit as st
|
| 17 |
-
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 18 |
-
|
| 19 |
-
# Load the base model
|
| 20 |
-
base_model_name = "Preetham04/Preetham04-sentiment-analysis"
|
| 21 |
-
tokenizer = AutoTokenizer.from_pretrained(base_model_name)
|
| 22 |
-
model = AutoModelForSequenceClassification.from_pretrained(base_model_name)
|
| 23 |
-
|
| 24 |
-
# Load the adapter configuration and model files
|
| 25 |
-
adapter_config_path = "config.json"
|
| 26 |
-
adapter_model_path = "model.safetensors"
|
| 27 |
-
|
| 28 |
-
# Load the adapter into the model
|
| 29 |
-
adapter_name = "custom_adapter" # Define your adapter name
|
| 30 |
-
model.load_adapter(adapter_config_path, model_file=adapter_model_path, load_as=adapter_name)
|
| 31 |
-
|
| 32 |
-
# Activate the adapter
|
| 33 |
-
model.set_active_adapters(adapter_name)
|
| 34 |
-
|
| 35 |
-
st.title("🤖 Chatbot with Adapter-Enhanced Model")
|
| 36 |
-
st.write("Interact with your custom adapter-enhanced model. Type a message and get responses!")
|
| 37 |
-
|
| 38 |
-
# Initialize or retrieve the chat history
|
| 39 |
-
if 'history' not in st.session_state:
|
| 40 |
-
st.session_state['history'] = []
|
| 41 |
-
|
| 42 |
-
# Initialize Gardio
|
| 43 |
-
chatbot = Gardio(model=model, tokenizer=tokenizer)
|
| 44 |
-
|
| 45 |
-
# Define responses for greetings
|
| 46 |
-
@chatbot.on_event("welcome")
|
| 47 |
-
def welcome_handler(payload):
|
| 48 |
-
return "Welcome! Type a message and get responses from the chatbot."
|
| 49 |
-
|
| 50 |
-
# Define responses for user messages
|
| 51 |
-
@chatbot.on_message
|
| 52 |
-
def message_handler(payload):
|
| 53 |
-
user_input = payload["message"]
|
| 54 |
-
response = chatbot.generate_response(user_input)
|
| 55 |
-
return response
|
| 56 |
-
|
| 57 |
-
# Run Gardio
|
| 58 |
-
if __name__ == "__main__":
|
| 59 |
-
chatbot.run()
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|