Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
import os
|
2 |
import json
|
3 |
-
import pyperclip
|
4 |
-
import gradio as gr
|
5 |
import vertexai
|
6 |
from vertexai.generative_models import GenerativeModel
|
7 |
import vertexai.preview.generative_models as generative_models
|
|
|
|
|
8 |
|
9 |
# Read the service account key JSON file path from environment variable
|
10 |
SERVICE_ACCOUNT_KEY_PATH = os.getenv("GOOGLE_APPLICATION_CREDENTIALS")
|
@@ -58,30 +58,34 @@ def generate(text):
|
|
58 |
return response_text if response_text else "No valid response generated or response was blocked."
|
59 |
|
60 |
except Exception as e:
|
61 |
-
return
|
62 |
|
63 |
def copy_to_clipboard(text):
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
-
|
71 |
-
|
72 |
-
# Chuunibyou Text Generator
|
73 |
-
Transform text into an elaborate and formal style with a Chuunibyou tone.
|
74 |
-
""")
|
75 |
-
|
76 |
-
with gr.Row():
|
77 |
-
with gr.Column(scale=2):
|
78 |
-
input_text = gr.Textbox(lines=2, placeholder="Enter text here...")
|
79 |
-
output_text = gr.Textbox(lines=4, interactive=False)
|
80 |
-
generate_button = gr.Button("Submit")
|
81 |
-
copy_button = gr.Button("Copy to Clipboard")
|
82 |
-
hidden_state = gr.State()
|
83 |
|
84 |
-
|
85 |
-
|
|
|
86 |
|
87 |
-
|
|
|
|
1 |
import os
|
2 |
import json
|
|
|
|
|
3 |
import vertexai
|
4 |
from vertexai.generative_models import GenerativeModel
|
5 |
import vertexai.preview.generative_models as generative_models
|
6 |
+
import gradio as gr
|
7 |
+
import pyperclip
|
8 |
|
9 |
# Read the service account key JSON file path from environment variable
|
10 |
SERVICE_ACCOUNT_KEY_PATH = os.getenv("GOOGLE_APPLICATION_CREDENTIALS")
|
|
|
58 |
return response_text if response_text else "No valid response generated or response was blocked."
|
59 |
|
60 |
except Exception as e:
|
61 |
+
return str(e)
|
62 |
|
63 |
def copy_to_clipboard(text):
|
64 |
+
pyperclip.copy(text)
|
65 |
+
return "Text copied to clipboard!"
|
66 |
+
|
67 |
+
iface = gr.Interface(
|
68 |
+
fn=generate,
|
69 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
|
70 |
+
outputs=gr.Textbox(visible=False),
|
71 |
+
title="Chuunibyou Text Generator",
|
72 |
+
description="Transform text into an elaborate and formal style with a Chuunibyou tone.",
|
73 |
+
live=False
|
74 |
+
)
|
75 |
+
|
76 |
+
def update_output(text):
|
77 |
+
return gr.update(value=text, visible=True)
|
78 |
+
|
79 |
+
iface_after_submit = iface.set_event_handlers(
|
80 |
+
submit=lambda x: update_output(generate(x))
|
81 |
+
)
|
82 |
|
83 |
+
copy_button = gr.Button("Copy to Clipboard")
|
84 |
+
copy_button.click(copy_to_clipboard, inputs=iface_after_submit.output_component, outputs=gr.Textbox(visible=True))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
|
86 |
+
iface_after_submit = gr.Column(
|
87 |
+
[iface_after_submit, copy_button]
|
88 |
+
)
|
89 |
|
90 |
+
if __name__ == "__main__":
|
91 |
+
iface_after_submit.launch()
|