Spaces:
Sleeping
Sleeping
Preetham04
commited on
Commit
•
00f8b37
1
Parent(s):
f4c7831
Update app.py
Browse files
app.py
CHANGED
@@ -53,42 +53,20 @@ if __name__ == "__main__":
|
|
53 |
chatbot.run()
|
54 |
"""
|
55 |
import gradio as gr
|
56 |
-
from transformers import
|
57 |
|
58 |
-
|
59 |
-
base_model_name = "Preetham04/sentiment-analysis"
|
60 |
-
tokenizer = AutoTokenizer.from_pretrained(base_model_name)
|
61 |
-
model = AutoModelForSequenceClassification.from_pretrained(base_model_name)
|
62 |
-
|
63 |
-
# Load the adapter configuration and model files
|
64 |
-
adapter_path = "model.safetensors" # Typically, this is a single path
|
65 |
-
|
66 |
-
# Load the adapter into the model
|
67 |
-
adapter_name = "custom_adapter" # Define your adapter name
|
68 |
-
model.load_adapter(adapter_path, load_as=adapter_name)
|
69 |
|
70 |
-
|
71 |
-
|
|
|
72 |
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
-
st.title("🤖 Chatbot with Adapter-Enhanced Model")
|
76 |
-
st.write("Interact with your custom adapter-enhanced model. Type a message and get responses!")
|
77 |
-
|
78 |
-
# Initialize or retrieve the chat history
|
79 |
-
if 'history' not in st.session_state:
|
80 |
-
st.session_state['history'] = []
|
81 |
-
|
82 |
-
# Initialize Gradio
|
83 |
-
chatbot = gr.Interface(fn=message_handler, inputs="text", outputs="text", live=True)
|
84 |
-
|
85 |
-
# Define responses for user messages
|
86 |
-
def message_handler(user_input):
|
87 |
-
inputs = tokenizer(user_input, return_tensors="pt")
|
88 |
-
outputs = model(**inputs)
|
89 |
-
response = tokenizer.decode(outputs.logits.argmax(dim=-1))
|
90 |
-
return response
|
91 |
-
|
92 |
-
# Run Gradio
|
93 |
if __name__ == "__main__":
|
94 |
-
|
|
|
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,
|
66 |
+
inputs="textbox",
|
67 |
+
outputs="text",
|
68 |
+
title="Sentiment- good or bad?",
|
69 |
+
)
|
70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
if __name__ == "__main__":
|
72 |
+
gradio_app.launch()
|