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