Preetham04 commited on
Commit
7fb0561
1 Parent(s): cd96437

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -57
app.py CHANGED
@@ -1,65 +1,11 @@
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
- from transformers import AutoTokenizer, AutoModelForSequenceClassification
12
-
13
- # Load the base model
14
- base_model_name = "Preetham04/sentiment-analysis"
15
- tokenizer = AutoTokenizer.from_pretrained(base_model_name)
16
- model = AutoModelForSequenceClassification.from_pretrained(base_model_name)
17
-
18
- # Load the adapter configuration and model files
19
- adapter_config_path = "config.json"
20
- adapter_model_path = "model.safetensors"
21
-
22
- # Load the adapter into the model
23
- adapter_name = "custom_adapter" # Define your adapter name
24
- model.load_adapter(config_path=adapter_config_path, adapter_path=adapter_model_path, adapter_name=adapter_name)
25
-
26
- # Activate the adapter
27
- model.set_active_adapters(adapter_name)
28
-
29
- st.title("🤖 Chatbot with Adapter-Enhanced Model")
30
- st.write("Interact with your custom adapter-enhanced model. Type a message and get responses!")
31
-
32
- # Initialize or retrieve the chat history
33
- if 'history' not in st.session_state:
34
- st.session_state['history'] = []
35
-
36
- # Initialize Gradio
37
- chatbot = Gradio(model=model, tokenizer=tokenizer)
38
-
39
- # Define responses for greetings
40
- @chatbot.on_event("welcome")
41
- def welcome_handler(payload):
42
- return "Welcome! Type a message and get responses from the chatbot."
43
-
44
- # Define responses for user messages
45
- @chatbot.on_message
46
- def message_handler(payload):
47
- user_input = payload["message"]
48
- response = chatbot.generate_response(user_input)
49
- return response
50
-
51
- # Run Gradio
52
- if __name__ == "__main__":
53
- chatbot.run()
54
- """
55
  import gradio as gr
56
  from transformers import pipeline
57
 
58
  pipeline = pipeline(task="text-classification", model="Preetham04/sentiment-analysis")
59
 
60
- def predict(input_img):
61
- predictions = pipeline(input_img)
62
- return input_img, {p["label"]: p["score"] for p in predictions}
63
 
64
  gradio_app = gr.Interface(
65
  predict,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
  pipeline = pipeline(task="text-classification", model="Preetham04/sentiment-analysis")
5
 
6
+ def predict(input_text):
7
+ predictions = pipeline(input_text)
8
+ return input_text, {p["label"]: p["score"] for p in predictions}
9
 
10
  gradio_app = gr.Interface(
11
  predict,