Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -12,7 +12,7 @@ def get_alternate_text(text, language):
|
|
12 |
"Authorization": f"Bearer {os.environ.get('OPENAI_API_KEY')}",
|
13 |
"Content-Type": "application/json",
|
14 |
}
|
15 |
-
system_prompt = f"Please rephrase this text in {language} in a manner that it is natural sounding, very concise but without any key information loss. Give 3 such texts separated by new line."
|
16 |
prompt = f"""Text:
|
17 |
---
|
18 |
{text}
|
@@ -27,25 +27,28 @@ def get_alternate_text(text, language):
|
|
27 |
"temperature": 0.4
|
28 |
}
|
29 |
response = requests.post(ENDPOINT, data=json.dumps(payload), headers=headers)
|
30 |
-
|
31 |
-
while
|
32 |
try:
|
33 |
-
|
34 |
except Exception as e:
|
35 |
print(e)
|
36 |
response = requests.post(ENDPOINT, data=json.dumps(payload), headers=headers)
|
37 |
continue
|
38 |
-
|
|
|
|
|
39 |
|
40 |
language = gr.Dropdown(LANGUAGES, value="Spanish", label="Language")
|
41 |
text = gr.Textbox(lines=4, label="Text")
|
|
|
|
|
42 |
|
43 |
interface = gr.Interface(
|
44 |
get_alternate_text,
|
45 |
[text, language],
|
46 |
-
|
47 |
-
title="Deepsync Text Rephraser"
|
48 |
-
description="Please note that this is a Rephraser tool and not a translation tool. So, the `language` field should match the language of the provided text."
|
49 |
)
|
50 |
|
51 |
if __name__=="__main__":
|
|
|
12 |
"Authorization": f"Bearer {os.environ.get('OPENAI_API_KEY')}",
|
13 |
"Content-Type": "application/json",
|
14 |
}
|
15 |
+
system_prompt = f"Please rephrase this text in {language} in lesser words in a manner that it is natural sounding, very concise but without any key information loss. Give 3 such texts separated by new line. Return only the texts without any numbering or bullets."
|
16 |
prompt = f"""Text:
|
17 |
---
|
18 |
{text}
|
|
|
27 |
"temperature": 0.4
|
28 |
}
|
29 |
response = requests.post(ENDPOINT, data=json.dumps(payload), headers=headers)
|
30 |
+
resp_text = None
|
31 |
+
while resp_text is None:
|
32 |
try:
|
33 |
+
resp_text = response.json().get('choices')[0]['message']['content'].strip("\n").replace('"', "")
|
34 |
except Exception as e:
|
35 |
print(e)
|
36 |
response = requests.post(ENDPOINT, data=json.dumps(payload), headers=headers)
|
37 |
continue
|
38 |
+
texts = list(filter(lambda x: len(x.strip()) > 0, resp_text.split("\n")))
|
39 |
+
counts = list(map(lambda x: len(x.split()), texts))
|
40 |
+
return len(text.split()), {"data": list(zip(texts, counts)), "headers": ["Alternatives", "Word Count"]}
|
41 |
|
42 |
language = gr.Dropdown(LANGUAGES, value="Spanish", label="Language")
|
43 |
text = gr.Textbox(lines=4, label="Text")
|
44 |
+
dataframe = gr.Dataframe(wrap=True)
|
45 |
+
word_count = gr.Textbox(lines=1, label="Word Count")
|
46 |
|
47 |
interface = gr.Interface(
|
48 |
get_alternate_text,
|
49 |
[text, language],
|
50 |
+
[word_count, dataframe],
|
51 |
+
title="Deepsync Text Rephraser"
|
|
|
52 |
)
|
53 |
|
54 |
if __name__=="__main__":
|