Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,32 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
def greet(name):
|
| 4 |
-
|
| 5 |
|
| 6 |
-
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 7 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
#def greet(name):
|
| 4 |
+
# return "Hello " + name + "!"
|
| 5 |
|
| 6 |
+
#iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 7 |
+
#iface.launch()
|
| 8 |
+
|
| 9 |
+
# Use a pipeline as a high-level helper
|
| 10 |
+
from transformers import pipeline
|
| 11 |
+
|
| 12 |
+
pipe = pipeline("text-generation", model="gpt2")
|
| 13 |
+
|
| 14 |
+
# Load model directly
|
| 15 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 16 |
+
|
| 17 |
+
tokenizer = AutoTokenizer.from_pretrained("gpt2")
|
| 18 |
+
model = AutoModelForCausalLM.from_pretrained("gpt2")
|
| 19 |
+
|
| 20 |
+
#get the text
|
| 21 |
+
text_input = "One upon a time there was a tree"
|
| 22 |
+
max_length = 100
|
| 23 |
+
temperature = 0.8
|
| 24 |
+
top_k = 100
|
| 25 |
+
|
| 26 |
+
input_ids = tokenizer.encode(text_input,return_tensors='pt')
|
| 27 |
+
|
| 28 |
+
output = model.generate(input_ids, max_length=max_length, temperature=temperature, top_k=top_k, do_sample = True)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
response = tokenizer.decode(output[0], skip_special_token=True)
|
| 32 |
+
print(response)
|