Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, pipeline
|
3 |
+
import torch
|
4 |
+
|
5 |
+
|
6 |
+
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained("akoksal/LongForm-OPT-2.7B")
|
8 |
+
generate = pipeline('text-generation', model='akoksal/LongForm-OPT-2.7B', tokenizer=tokenizer)
|
9 |
+
|
10 |
+
|
11 |
+
def predict(instruction, topp, temperature):
|
12 |
+
if "[EOI]" not in instruction:
|
13 |
+
instruction = instruction + " [EOI]"
|
14 |
+
x = generate(instruction,
|
15 |
+
do_sample=True,
|
16 |
+
max_length=64,
|
17 |
+
top_p=topp,
|
18 |
+
num_return_sequences=1,
|
19 |
+
temperature=temperature
|
20 |
+
)[0]["generated_text"]
|
21 |
+
|
22 |
+
return x
|
23 |
+
|
24 |
+
iface = gr.Interface(fn=predict, inputs=["text",\\
|
25 |
+
gr.inputs.Slider(0, 2, default=1, label="temperature"),\
|
26 |
+
gr.inputs.Slider(0, 1, default=0.90, label="top_p")]
|
27 |
+
, outputs="text")
|
28 |
+
iface.launch()
|