hihi222 commited on
Commit
89aacac
1 Parent(s): 609d13a

code changes

Browse files
Files changed (2) hide show
  1. app.py +107 -2
  2. requirements.txt +2 -0
app.py CHANGED
@@ -1,7 +1,112 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  def greet(name):
4
  return "Hello " + name + "!!"
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ import re
5
+
6
+ email_subject_pipeline = pipeline("text-generation", model="kkasiviswanath/distilgpt2_email_subject_summarizer")
7
+
8
+ def clean_subject(response):
9
+ print(response)
10
+ lst = response.split('<|sep|>')
11
+ if (len(lst) >= 2):
12
+ response = lst[1].replace("<|endoftext|>","")
13
+ return response
14
+
15
+
16
+ def generate_subject(email: str):
17
+ prompt = f"<|startoftext|> {email} <|sep|>"
18
+
19
+ # Use the pipeline to generate the text
20
+ sample_outputs = email_subject_pipeline(prompt, max_new_tokens=12, num_beams=5, early_stopping=True, num_return_sequences=1)
21
+
22
+ # The pipeline output is a list of dictionaries, so extract the generated text
23
+ subject = clean_subject(sample_outputs[0]['generated_text'])
24
+ return subject
25
+
26
+
27
 
28
  def greet(name):
29
  return "Hello " + name + "!!"
30
 
31
+ theme = gr.themes.ThemeClass.from_hub("freddyaboulton/dracula_revamped")
32
+
33
+ with gr.Blocks(theme=theme) as demo:
34
+ gr.Markdown("# AI-based Generative QA System")
35
+ with gr.Tab("Email Subject Line Generation"):
36
+ gr.Markdown("To generate subject line for your email, copy/paste or type email in the box and click on Generate Subject")
37
+ with gr.Row():
38
+ with gr.Column(scale=2):
39
+ text_input_email = gr.Textbox(lines=8, label="Email")
40
+ text_output_subject = gr.Textbox(label="Generated Subject")
41
+ with gr.Column(scale=1):
42
+ with gr.Column(scale=1):
43
+ gr.Markdown(
44
+ """
45
+ ## Team 17
46
+ ```
47
+
48
+ Archit Garg
49
+ Dinesh
50
+ Chandrasekhar B
51
+ K Kasi Viswanath
52
+ ```
53
+ ## Model
54
+ ```
55
+ Fine tuned gpt2-medium
56
+
57
+ ```
58
+ ## Training Dataset
59
+ ```
60
+ AESLC
61
+ ```
62
+
63
+ """)
64
+ with gr.Row():
65
+ with gr.Column(scale=2):
66
+ btn_generate_subject = gr.Button("Generate Subject")
67
+ with gr.Column():
68
+ gr.Markdown(
69
+ """
70
+ """)
71
+ with gr.Tab("Question Answering on AIML Queries"):
72
+ with gr.Column(scale=1):
73
+ gr.Markdown("To generate answer for your question, copy/paste or type question in the box and click on Generate Answer")
74
+ with gr.Row():
75
+ with gr.Column(scale=2):
76
+ text_input_question = gr.Textbox(label="Question")
77
+ text_output_answer = gr.Textbox(lines=8, label="Generated Answer")
78
+ with gr.Column(scale=1):
79
+ with gr.Column(scale=1):
80
+ gr.Markdown(
81
+ """
82
+ ## Team 17
83
+ ```
84
+
85
+ Archit Garg
86
+ Dinesh
87
+ Chandrasekhar B
88
+ K Kasi Viswanath
89
+ ```
90
+ ## Model
91
+ ```
92
+ Fine tuned gpt2-medium
93
+
94
+ ```
95
+ ## Training Dataset
96
+ ```
97
+ Custom
98
+ ```
99
+
100
+ """)
101
+ with gr.Row():
102
+ with gr.Column(scale=2):
103
+ btn_generated_answer = gr.Button("Generate Answer")
104
+ with gr.Column():
105
+ gr.Markdown(
106
+ """
107
+ """)
108
+ btn_generate_subject.click(generate_subject, inputs=text_input_email, outputs=text_output_subject)
109
+
110
+ btn_generated_answer.click(greet, inputs="text", outputs="text")
111
+
112
+ demo.launch(share=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ torch
2
+ transformers