Akbartus commited on
Commit
da51d36
·
1 Parent(s): 49fca37

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -4
app.py CHANGED
@@ -1,5 +1,68 @@
1
- # It is possible to download without any issues almost any model with one line of code. Choose any model, get its link, and add before it "huggingface/".
2
- # import gradio and define it as a variable name
3
  import gradio as gr
4
- # load interface related to gpt2 and launch it.
5
- gr.Interface.load("huggingface/mrm8488/t5-base-finetuned-question-generation-ap").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import AutoModelWithLMHead, AutoTokenizer
3
+
4
+ tokenizer = AutoTokenizer.from_pretrained("mrm8488/t5-base-finetuned-question-generation-ap")
5
+ model = AutoModelWithLMHead.from_pretrained("mrm8488/t5-base-finetuned-question-generation-ap")
6
+
7
+ def get_question(context, answer, max_length=64):
8
+ input_text = "answer: %s context: %s </s>" % (answer, context)
9
+ features = tokenizer([input_text], return_tensors='pt')
10
+
11
+ output = model.generate(input_ids=features['input_ids'],
12
+ attention_mask=features['attention_mask'],
13
+ max_length=max_length)
14
+
15
+ return tokenizer.decode(output[0])[16:-4]
16
+
17
+ examples = [["The world's first piece of software was written by a computer scientist named Tom Kilburn in 1948.", "1948"], ["The world's first piece of software was written by a computer scientist named Tom Kilburn in 1948.", "Tom Kilburn"], ["The world's first piece of software was written by a computer scientist named Tom Kilburn in 1948.", "computer scientist"]]
18
+
19
+ css = """
20
+ footer {display:none !important}
21
+ .output-markdown{display:none !important}
22
+ .gr-button-primary {
23
+ z-index: 14;
24
+ height: 43px;
25
+ width: 130px;
26
+ left: 0px;
27
+ top: 0px;
28
+ padding: 0px;
29
+ cursor: pointer !important;
30
+ background: none rgb(17, 20, 45) !important;
31
+ border: none !important;
32
+ text-align: center !important;
33
+ font-family: Poppins !important;
34
+ font-size: 14px !important;
35
+ font-weight: 500 !important;
36
+ color: rgb(255, 255, 255) !important;
37
+ line-height: 1 !important;
38
+ border-radius: 12px !important;
39
+ transition: box-shadow 200ms ease 0s, background 200ms ease 0s !important;
40
+ box-shadow: none !important;
41
+ }
42
+ .gr-button-primary:hover{
43
+ z-index: 14;
44
+ height: 43px;
45
+ width: 130px;
46
+ left: 0px;
47
+ top: 0px;
48
+ padding: 0px;
49
+ cursor: pointer !important;
50
+ background: none rgb(37, 56, 133) !important;
51
+ border: none !important;
52
+ text-align: center !important;
53
+ font-family: Poppins !important;
54
+ font-size: 14px !important;
55
+ font-weight: 500 !important;
56
+ color: rgb(255, 255, 255) !important;
57
+ line-height: 1 !important;
58
+ border-radius: 12px !important;
59
+ transition: box-shadow 200ms ease 0s, background 200ms ease 0s !important;
60
+ box-shadow: rgb(0 0 0 / 23%) 0px 1px 7px 0px !important;
61
+ }
62
+ .hover\:bg-orange-50:hover {
63
+ --tw-bg-opacity: 1 !important;
64
+ background-color: rgb(229,225,255) !important;
65
+ }
66
+ """
67
+ demo = gr.Interface(fn=get_question, inputs=[gr.Textbox(lines=3, placeholder="Enter text here", label="Input # 1 - Context"), gr.Textbox(lines=1, label="Input # 2 - Answer")], outputs=gr.Textbox(label="Output - Generated Question"), title="Question Generator | Data Science Dojo", examples=examples, css=css)
68
+ demo.launch()