Spaces:
Sleeping
Sleeping
Commit
·
89b0bb7
1
Parent(s):
9146528
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import openai
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
def summarize(api_key,text):
|
5 |
+
openai.api_key = api_key
|
6 |
+
|
7 |
+
prompt = f"""Take deep breath and summarize the main
|
8 |
+
essential innovative idea in simple and cohesive one paragraph
|
9 |
+
and the first sentence summarize it all: {text}"""
|
10 |
+
response = openai.ChatCompletion.create(
|
11 |
+
model="gpt-4",
|
12 |
+
messages=[ {
|
13 |
+
"role": "system",
|
14 |
+
"content": "You professional writing assistant."
|
15 |
+
},
|
16 |
+
{"role": "user",
|
17 |
+
"content": prompt
|
18 |
+
}],
|
19 |
+
|
20 |
+
temperature=0,
|
21 |
+
max_tokens=1024,
|
22 |
+
top_p=1,
|
23 |
+
frequency_penalty=0.5,
|
24 |
+
presence_penalty=0.5
|
25 |
+
)
|
26 |
+
summary = response.choices[0].message["content"]
|
27 |
+
return summary
|
28 |
+
|
29 |
+
|
30 |
+
|
31 |
+
def main():
|
32 |
+
interface = gr.Interface(
|
33 |
+
fn=summarize,
|
34 |
+
inputs=[
|
35 |
+
gr.inputs.Textbox(label="API Key", type="password"),
|
36 |
+
gr.inputs.Textbox(label="Text to Summarize")
|
37 |
+
],
|
38 |
+
outputs=gr.outputs.Textbox(label="Summary"),
|
39 |
+
live=True,
|
40 |
+
title="Ibrahim App : GPT4 One Paragraph Summary",
|
41 |
+
description="Summarize text using GPT-4 in one Paragraph."
|
42 |
+
)
|
43 |
+
interface.launch()
|
44 |
+
|
45 |
+
if __name__ == "__main__":
|
46 |
+
main()
|
47 |
+
|
48 |
+
|