Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import openai
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
def summarize(api_key,text):
|
5 |
+
|
6 |
+
openai.api_key = api_key
|
7 |
+
|
8 |
+
prompt = f"""Take deep breath and summarize the main
|
9 |
+
|
10 |
+
essential innovative idea in simple and cohesive one paragraph
|
11 |
+
|
12 |
+
and the first sentence summarize it all: {text}"""
|
13 |
+
|
14 |
+
response = openai.ChatCompletion.create(
|
15 |
+
|
16 |
+
model="gpt-4",
|
17 |
+
|
18 |
+
messages=[ {
|
19 |
+
|
20 |
+
"role": "system",
|
21 |
+
|
22 |
+
"content": "You professional writing assistant."
|
23 |
+
|
24 |
+
},
|
25 |
+
|
26 |
+
{"role": "user",
|
27 |
+
|
28 |
+
"content": prompt
|
29 |
+
|
30 |
+
}],
|
31 |
+
|
32 |
+
|
33 |
+
temperature=0,
|
34 |
+
|
35 |
+
max_tokens=1024,
|
36 |
+
|
37 |
+
top_p=1,
|
38 |
+
|
39 |
+
frequency_penalty=0.5,
|
40 |
+
|
41 |
+
presence_penalty=0.5
|
42 |
+
|
43 |
+
)
|
44 |
+
|
45 |
+
summary = response.choices[0].message["content"]
|
46 |
+
|
47 |
+
return summary
|
48 |
+
|
49 |
+
def main():
|
50 |
+
|
51 |
+
interface = gr.Interface(
|
52 |
+
|
53 |
+
fn=summarize,
|
54 |
+
|
55 |
+
inputs=[
|
56 |
+
|
57 |
+
gr.Textbox(label="API Key", type="password"),
|
58 |
+
|
59 |
+
gr.Textbox(label="Text to Summarize",
|
60 |
+
|
61 |
+
placeholder="Enter your text here...", lines=20 )
|
62 |
+
|
63 |
+
],
|
64 |
+
|
65 |
+
outputs=gr.Textbox(label="Summary",lines=20),
|
66 |
+
|
67 |
+
live=False,
|
68 |
+
|
69 |
+
title="Ibrahimian GPT-4 Summarizer",
|
70 |
+
|
71 |
+
description="One cohesive summarization using GPT-4",
|
72 |
+
|
73 |
+
submit_label="Submit"
|
74 |
+
|
75 |
+
)
|
76 |
+
|
77 |
+
interface.launch()
|
78 |
+
|
79 |
+
|
80 |
+
|
81 |
+
if __name__ == "__main__":
|
82 |
+
|
83 |
+
main()
|