Spaces:
Build error
Build error
Commit
·
34e1bee
1
Parent(s):
9bc2b3f
init
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import utils, pipeline, set_seed
|
| 3 |
+
import torch
|
| 4 |
+
from torch.nn import functional as F
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
device = 'cpu'
|
| 8 |
+
|
| 9 |
+
class Generator:
|
| 10 |
+
def __init__(self) -> None:
|
| 11 |
+
self.generator = pipeline('text-generation', model="EleutherAI/gpt-neo-1.3B", do_sample=True)
|
| 12 |
+
self.history = "Human: Can you tell me the weather forecast for tomorrow?\nAssistant: Try checking a weather app like a normal person.\nHuman: Can you help me find a good restaurant in the area\nAssistant: Try asking someone with a functioning sense of taste.\n"
|
| 13 |
+
|
| 14 |
+
def generate(self, text, max_len=400, temp=0.8):
|
| 15 |
+
self.history += f'Human: {text}\nAssistant: '
|
| 16 |
+
gen_text = self.generator(self.history, max_length=max_len, temperature=temp)[0]['generated_text']
|
| 17 |
+
gen_text = gen_text.split('Human:')[0]
|
| 18 |
+
self.history += gen_text
|
| 19 |
+
return gen_text
|
| 20 |
+
|
| 21 |
+
gen = Generator()
|
| 22 |
+
|
| 23 |
+
def generate(text):
|
| 24 |
+
return gen.generate(text)
|
| 25 |
+
|
| 26 |
+
iface = gr.Interface(fn=generate, inputs="text", outputs="textbox")
|
| 27 |
+
iface.launch()
|