Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,12 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
|
4 |
-
|
5 |
|
6 |
-
#
|
7 |
-
|
|
|
|
|
8 |
|
9 |
title = "OPT-2.7B"
|
10 |
description = "This demo uses meta's opt-2.7b model prompt tuned on the Stanford Sentiment Treebank-5 way dataset to only output the sentiment of a given text."
|
@@ -12,8 +14,14 @@ article = "<p style='text-align: center'><a href='https://arxiv.org/pdf/2104.086
|
|
12 |
|
13 |
|
14 |
def sentiment(text):
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
iface = gr.Interface(fn=sentiment, inputs="text", outputs="text", title=title,
|
18 |
description=description, article=article)
|
19 |
iface.launch()
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
|
4 |
+
from transformers import pipeline, AutoTokenizer, AutoModel
|
5 |
|
6 |
+
#pipe = pipeline("text-generation", model="furquan/opt_2_7_b_prompt_tuned_sentiment_analysis", trust_remote_code=True, cache_dir="/local/home/furquanh/myProjects/week12/").to('cuda')
|
7 |
+
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained("furquan/opt_2_7_b_prompt_tuned_sentiment_analysis", trust_remote_code=True)
|
9 |
+
model = AutoModel.from_pretrained("furquan/opt_2_7_b_prompt_tuned_sentiment_analysis", trust_remote_code=True)
|
10 |
|
11 |
title = "OPT-2.7B"
|
12 |
description = "This demo uses meta's opt-2.7b model prompt tuned on the Stanford Sentiment Treebank-5 way dataset to only output the sentiment of a given text."
|
|
|
14 |
|
15 |
|
16 |
def sentiment(text):
|
17 |
+
tokenized = tokenizer(text, return_tensors='pt')
|
18 |
+
with torch.no_grad():
|
19 |
+
outputs = model.generate(
|
20 |
+
input_ids=tokenized["input_ids"], attention_mask=tokenized["attention_mask"]
|
21 |
+
)
|
22 |
+
return f"text: {text} Sentiment: {tokenizer.decode(outputs[0][-3:], skip_special_tokens=True)}"
|
23 |
|
24 |
iface = gr.Interface(fn=sentiment, inputs="text", outputs="text", title=title,
|
25 |
description=description, article=article)
|
26 |
iface.launch()
|
27 |
+
|