Spaces:
Runtime error
Runtime error
Update archives/modified_version.py
Browse files- archives/modified_version.py +23 -15
archives/modified_version.py
CHANGED
|
@@ -6,6 +6,10 @@ from sentence_transformers import SentenceTransformer
|
|
| 6 |
from utils import get_init, parse_instructions
|
| 7 |
import re
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
# from urllib.parse import quote_plus
|
| 10 |
# from pymongo import MongoClient
|
| 11 |
|
|
@@ -15,27 +19,31 @@ import re
|
|
| 15 |
# db = client.recurrentGPT_db
|
| 16 |
# log = db.log
|
| 17 |
|
| 18 |
-
|
|
|
|
| 19 |
|
|
|
|
| 20 |
|
| 21 |
-
#
|
|
|
|
| 22 |
embedder = SentenceTransformer('multi-qa-mpnet-base-cos-v1')
|
| 23 |
|
| 24 |
-
|
|
|
|
| 25 |
if description == "":
|
| 26 |
description = ""
|
| 27 |
else:
|
| 28 |
description = " about " + description
|
| 29 |
return f"""
|
| 30 |
-
Please write a {
|
| 31 |
-
Begin with the
|
| 32 |
-
Next, write an outline for the first
|
| 33 |
-
Write the first three paragraphs with their indication of the
|
| 34 |
Write a summary that captures the key information of the three paragraphs.
|
| 35 |
-
Finally, write three different instructions for what to write next, each containing around five sentences. Each instruction should present a possible, interesting continuation of the
|
| 36 |
The output format should follow these guidelines:
|
| 37 |
-
Name: <name of the
|
| 38 |
-
Outline: <outline for the first
|
| 39 |
Paragraph 1: <content for paragraph 1>
|
| 40 |
Paragraph 2: <content for paragraph 2>
|
| 41 |
Paragraph 3: <content for paragraph 3>
|
|
@@ -46,14 +54,14 @@ Instruction 3: <content for instruction 3>
|
|
| 46 |
Make sure to be precise and follow the output format strictly.
|
| 47 |
"""
|
| 48 |
|
| 49 |
-
def init(
|
| 50 |
-
if
|
| 51 |
-
|
| 52 |
global _CACHE
|
| 53 |
cookie = request.headers['cookie']
|
| 54 |
cookie = cookie.split('; _gat_gtag')[0]
|
| 55 |
# prepare first init
|
| 56 |
-
init_paragraphs = get_init(text=init_prompt(
|
| 57 |
# print(init_paragraphs)
|
| 58 |
start_input_to_human = {
|
| 59 |
'output_paragraph': init_paragraphs['Paragraph 3'],
|
|
@@ -64,7 +72,7 @@ def init(novel_type, description, request: gr.Request):
|
|
| 64 |
|
| 65 |
_CACHE[cookie] = {"start_input_to_human": start_input_to_human,
|
| 66 |
"init_paragraphs": init_paragraphs}
|
| 67 |
-
written_paras = f"""Title: {init_paragraphs['name']}
|
| 68 |
Outline: {init_paragraphs['Outline']}
|
| 69 |
Paragraphs:
|
| 70 |
{start_input_to_human['input_paragraph']}"""
|
|
|
|
| 6 |
from utils import get_init, parse_instructions
|
| 7 |
import re
|
| 8 |
|
| 9 |
+
###################################################################################################################################################################
|
| 10 |
+
###################################################################################################################################################################
|
| 11 |
+
# TODO: add user database
|
| 12 |
+
|
| 13 |
# from urllib.parse import quote_plus
|
| 14 |
# from pymongo import MongoClient
|
| 15 |
|
|
|
|
| 19 |
# db = client.recurrentGPT_db
|
| 20 |
# log = db.log
|
| 21 |
|
| 22 |
+
###################################################################################################################################################################
|
| 23 |
+
###################################################################################################################################################################
|
| 24 |
|
| 25 |
+
_CACHE = {}
|
| 26 |
|
| 27 |
+
# TODO : try with different embedding models
|
| 28 |
+
## Build the semantic search model
|
| 29 |
embedder = SentenceTransformer('multi-qa-mpnet-base-cos-v1')
|
| 30 |
|
| 31 |
+
# TODO: make a prompt class
|
| 32 |
+
def init_prompt(text_type, description, structure, units, tone):
|
| 33 |
if description == "":
|
| 34 |
description = ""
|
| 35 |
else:
|
| 36 |
description = " about " + description
|
| 37 |
return f"""
|
| 38 |
+
Please write a {text_type} about {description} with {units} {structure}. Follow the format below precisely:
|
| 39 |
+
Begin with the title of the {text_type}.
|
| 40 |
+
Next, write an outline for the first {structure}. The outline should describe the {description} and the beginning of the {text_type}.
|
| 41 |
+
Write the first three paragraphs with their indication of the {text_type} based on your outline. Write in a {tone} style and take your time to set the context.
|
| 42 |
Write a summary that captures the key information of the three paragraphs.
|
| 43 |
+
Finally, write three different instructions for what to write next, each containing around five sentences. Each instruction should present a possible, interesting continuation of the {text_type}.
|
| 44 |
The output format should follow these guidelines:
|
| 45 |
+
Name: <name of the {text_type}>
|
| 46 |
+
Outline: <outline for the first {structure}>
|
| 47 |
Paragraph 1: <content for paragraph 1>
|
| 48 |
Paragraph 2: <content for paragraph 2>
|
| 49 |
Paragraph 3: <content for paragraph 3>
|
|
|
|
| 54 |
Make sure to be precise and follow the output format strictly.
|
| 55 |
"""
|
| 56 |
|
| 57 |
+
def init(text_type, description, request: gr.Request):
|
| 58 |
+
if tex_type == "":
|
| 59 |
+
text_type = "Linkedin post"
|
| 60 |
global _CACHE
|
| 61 |
cookie = request.headers['cookie']
|
| 62 |
cookie = cookie.split('; _gat_gtag')[0]
|
| 63 |
# prepare first init
|
| 64 |
+
init_paragraphs = get_init(text=init_prompt(text_type, description, structure, units, tone))
|
| 65 |
# print(init_paragraphs)
|
| 66 |
start_input_to_human = {
|
| 67 |
'output_paragraph': init_paragraphs['Paragraph 3'],
|
|
|
|
| 72 |
|
| 73 |
_CACHE[cookie] = {"start_input_to_human": start_input_to_human,
|
| 74 |
"init_paragraphs": init_paragraphs}
|
| 75 |
+
written_paras = f"""Title: {init_paragraphs['name']}
|
| 76 |
Outline: {init_paragraphs['Outline']}
|
| 77 |
Paragraphs:
|
| 78 |
{start_input_to_human['input_paragraph']}"""
|