Spaces:
Sleeping
Sleeping
prabinpanta0
commited on
Commit
•
0bc7254
1
Parent(s):
cd58eea
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import vertexai
|
2 |
+
from vertexai.generative_models import GenerativeModel
|
3 |
+
import vertexai.preview.generative_models as generative_models
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
def generate(text):
|
7 |
+
vertexai.init(project="idyllic-now-424815-h2", location="us-central1")
|
8 |
+
model = GenerativeModel(
|
9 |
+
"gemini-1.5-flash-001",
|
10 |
+
system_instruction=[
|
11 |
+
'Objective', text, 'Instructions', 'Use words like "thou," "thee," "thy," "henceforth," "forsooth," and "verily."',
|
12 |
+
'Transform sentences to be elaborate and formal.',
|
13 |
+
'Maintain a delusional nobleman tone, addressing others as if they are of lower status.',
|
14 |
+
'Examples', ':', 'Input', ': "Hey, what\'s up?"', 'Output', ': "Greetings, fair compatriot! What news dost thou bring?"',
|
15 |
+
'Input', ': "Can you help me with this?"', 'Output', ': "Might I entreat thee to lend thine esteemed assistance in this matter?"',
|
16 |
+
'Input', ': "I don\'t like this."', 'Output', ': "I find this matter to be most displeasing and beneath my esteemed tastes."',
|
17 |
+
'Input', ': "You did a good job."', 'Output', ': "Thy efforts are commendable, and thou hast performed admirably."',
|
18 |
+
'Input', ': "See you later."', 'Output', ': "Until we meet again, may fortune smile upon thee."',
|
19 |
+
'Keep the original meaning, but make it sound like a nobleman from a fantasy world.'
|
20 |
+
]
|
21 |
+
)
|
22 |
+
generation_config = {
|
23 |
+
'max_output_tokens': 3019,
|
24 |
+
'temperature': 1,
|
25 |
+
'top_p': 0.32,
|
26 |
+
}
|
27 |
+
safety_settings = {
|
28 |
+
generative_models.HarmCategory.HARM_CATEGORY_HATE_SPEECH: generative_models.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
|
29 |
+
generative_models.HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: generative_models.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
|
30 |
+
generative_models.HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: generative_models.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
|
31 |
+
generative_models.HarmCategory.HARM_CATEGORY_HARASSMENT: generative_models.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
|
32 |
+
}
|
33 |
+
responses = model.generate_content(
|
34 |
+
[text],
|
35 |
+
generation_config=generation_config,
|
36 |
+
safety_settings=safety_settings,
|
37 |
+
stream=True,
|
38 |
+
)
|
39 |
+
|
40 |
+
response_text = ""
|
41 |
+
for response in responses:
|
42 |
+
response_text += response.text
|
43 |
+
|
44 |
+
return response_text
|
45 |
+
|
46 |
+
iface = gr.Interface(
|
47 |
+
fn=generate,
|
48 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter text here..."),
|
49 |
+
outputs="text",
|
50 |
+
title="Chuunibyou Text Generator",
|
51 |
+
description="Transform text into an elaborate and formal style with a nobleman tone."
|
52 |
+
)
|
53 |
+
|
54 |
+
if __name__ == "__main__":
|
55 |
+
iface.launch()
|