Spaces:
Runtime error
Runtime error
Commit
·
debfcf8
1
Parent(s):
8072598
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
import pandas as pd
|
4 |
+
from datasets import load_dataset
|
5 |
+
|
6 |
+
|
7 |
+
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
8 |
+
device = 'cpu' # if you have a GPU
|
9 |
+
|
10 |
+
tokenizer = T5Tokenizer.from_pretrained('stanfordnlp/SteamSHP-flan-t5-large')
|
11 |
+
model = T5ForConditionalGeneration.from_pretrained('stanfordnlp/SteamSHP-flan-t5-large').to(device)
|
12 |
+
|
13 |
+
def process():
|
14 |
+
input_text = "POST: Instacart gave me 50 pounds of limes instead of 5 pounds... what the hell do I do with 50 pounds of limes? I've already donated a bunch and gave a bunch away. I'm planning on making a bunch of lime-themed cocktails, but... jeez. Ceviche? \n\n RESPONSE A: Lime juice, and zest, then freeze in small quantities.\n\n RESPONSE B: Lime marmalade lol\n\n Which response is better? RESPONSE"
|
15 |
+
x = tokenizer([input_text], return_tensors='pt').input_ids.to(device)
|
16 |
+
y = model.generate(x, max_new_tokens=1)
|
17 |
+
return tokenizer.batch_decode(y, skip_special_tokens=True)[0]
|
18 |
+
|
19 |
+
title = "Compare Instruction Models to see which one is more helpful"
|
20 |
+
interface = gr.Interface(fn=process,
|
21 |
+
#inputs=[gr.Image(type="pil"), gr.Textbox(label="Question")],
|
22 |
+
outputs=[,
|
23 |
+
gr.Textbox(label = "Responses")
|
24 |
+
],
|
25 |
+
title=title,
|
26 |
+
)
|
27 |
+
|
28 |
+
interface.launch(debug=True)
|