Preetham04 commited on
Commit
eae976d
1 Parent(s): 6960b0b

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ import gradio as gr
11
+ import streamlit as st
12
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
13
+
14
+ # Load the base model
15
+ base_model_name = "Preetham04/Preetham04-sentiment-analysis"
16
+ tokenizer = AutoTokenizer.from_pretrained(base_model_name)
17
+ model = AutoModelForSequenceClassification.from_pretrained(base_model_name)
18
+
19
+ # Load the adapter configuration and model files
20
+ adapter_config_path = "config.json"
21
+ adapter_model_path = "model.safetensors"
22
+
23
+ # Load the adapter into the model
24
+ adapter_name = "custom_adapter" # Define your adapter name
25
+ model.load_adapter(adapter_config_path, model_file=adapter_model_path, load_as=adapter_name)
26
+
27
+ # Activate the adapter
28
+ model.set_active_adapters(adapter_name)
29
+
30
+ st.title("🤖 Chatbot with Adapter-Enhanced Model")
31
+ st.write("Interact with your custom adapter-enhanced model. Type a message and get responses!")
32
+
33
+ # Initialize or retrieve the chat history
34
+ if 'history' not in st.session_state:
35
+ st.session_state['history'] = []
36
+
37
+ # Initialize Gradio
38
+ chatbot = Gradio(model=model, tokenizer=tokenizer)
39
+
40
+ # Define responses for greetings
41
+ @chatbot.on_event("welcome")
42
+ def welcome_handler(payload):
43
+ return "Welcome! Type a message and get responses from the chatbot."
44
+
45
+ # Define responses for user messages
46
+ @chatbot.on_message
47
+ def message_handler(payload):
48
+ user_input = payload["message"]
49
+ response = chatbot.generate_response(user_input)
50
+ return response
51
+
52
+ # Run Gradio
53
+ if __name__ == "__main__":
54
+ chatbot.run()
55
+