sudip1310 commited on
Commit
65b0852
1 Parent(s): 1e199d0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import T5Tokenizer, T5ForConditionalGeneration
3
+ from transformers.optimization import Adafactor
4
+ import time
5
+ import warnings
6
+
7
+ model = T5ForConditionalGeneration.from_pretrained('/content/pytoch_model.bin', return_dict=True,config='t5-base-config.json')
8
+
9
+ def generate(text):
10
+ model.eval()
11
+ input_ids = tokenizer.encode("WebNLG:{} </s>".format(text), return_tensors="pt") # Batch size 1
12
+ # input_ids.to(dev)
13
+ s = time.time()
14
+ outputs = model.generate(input_ids)
15
+ gen_text=tokenizer.decode(outputs[0]).replace('<pad>','').replace('</s>','')
16
+ elapsed = time.time() - s
17
+ print('Generated in {} seconds'.format(str(elapsed)[:4]))
18
+
19
+
20
+ return gen_text
21
+
22
+
23
+ import gradio as gr
24
+
25
+
26
+
27
+ # Define the Gradio interface
28
+ iface = gr.Interface(
29
+ fn=generate, # Replace with your actual function
30
+ inputs=gr.inputs.Textbox(lines=2, placeholder="Enter text here..."),
31
+ outputs=gr.outputs.Textbox(),
32
+ title="Text Generation App",
33
+ description="Enter some text and see the generated output.",
34
+ )
35
+
36
+ # Launch the Gradio interface
37
+ iface.launch()