Nageswaran commited on
Commit
ca21581
·
verified ·
1 Parent(s): 4d88c1c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ## Setup and Imports
3
+ """
4
+
5
+ # import os
6
+ # os.environ["KERAS_BACKEND"] = "jax"
7
+ import keras_core as keras
8
+ import keras_nlp
9
+ import gradio as gr
10
+ from huggingface_hub import Repository
11
+
12
+ import keras
13
+ from keras.optimizers import Adam
14
+ from keras.losses import SparseCategoricalCrossentropy
15
+ import keras_nlp
16
+
17
+ """## Get the repository"""
18
+
19
+ repo = Repository(
20
+ local_dir="title-generator-using-summary-gpt2-llm",
21
+ clone_from="Nageswaran/title-generator-using-summary-gpt2-llm",
22
+ )
23
+
24
+ """## Build the model"""
25
+
26
+ gpt2_lm = keras.models.load_model(
27
+ "title-generator-using-summary-gpt2-llm/gpt2_lm.keras"
28
+ )
29
+
30
+ title="Summary to Title"
31
+ description="GPT2 Model for summary to title."
32
+
33
+ def get_title(summary):
34
+ summary = summary.replace("\n", " ")
35
+ output = gpt2_lm.generate(f"Summary: {summary} Title:", max_length=600)
36
+ title = output.split("Title:")[1]
37
+ return title
38
+
39
+ """## Build the space and launch it"""
40
+
41
+ gpt_space = gr.Interface(
42
+ fn=get_title,
43
+ inputs=gr.Textbox(label="Summary"),
44
+ outputs=gr.Textbox(label="Title"),
45
+ title=title,
46
+ description=description,
47
+ )
48
+
49
+ gpt_space.launch()