clothing_bert / app.py
Preetham04's picture
Update app.py
00f8b37 verified
raw
history blame
No virus
2.1 kB
# -*- 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
from transformers import AutoTokenizer, AutoModelForSequenceClassification
# Load the base model
base_model_name = "Preetham04/sentiment-analysis"
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(config_path=adapter_config_path, adapter_path=adapter_model_path, adapter_name=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()
"""
import gradio as gr
from transformers import pipeline
pipeline = pipeline(task="text-classification", model="Preetham04/sentiment-analysis")
def predict(input_img):
predictions = pipeline(input_img)
return input_img, {p["label"]: p["score"] for p in predictions}
gradio_app = gr.Interface(
predict,
inputs="textbox",
outputs="text",
title="Sentiment- good or bad?",
)
if __name__ == "__main__":
gradio_app.launch()