prabinpanta0 commited on
Commit
c598300
1 Parent(s): 833b0e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -8
app.py CHANGED
@@ -4,6 +4,7 @@ import vertexai
4
  from vertexai.generative_models import GenerativeModel
5
  import vertexai.preview.generative_models as generative_models
6
  import gradio as gr
 
7
  # Read the service account key JSON file path from environment variable
8
  SERVICE_ACCOUNT_KEY_PATH = os.getenv("GOOGLE_APPLICATION_CREDENTIALS")
9
 
@@ -58,13 +59,34 @@ def generate(text):
58
  except Exception as e:
59
  return str(e)
60
 
61
- iface = gr.Interface(
62
- fn=generate,
63
- inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
64
- outputs="text",
65
- title="Chuunibyou Text Generator",
66
- description="Transform text into an elaborate and formal style with a nobleman tone."
67
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
  if __name__ == "__main__":
70
- iface.launch()
 
4
  from vertexai.generative_models import GenerativeModel
5
  import vertexai.preview.generative_models as generative_models
6
  import gradio as gr
7
+
8
  # Read the service account key JSON file path from environment variable
9
  SERVICE_ACCOUNT_KEY_PATH = os.getenv("GOOGLE_APPLICATION_CREDENTIALS")
10
 
 
59
  except Exception as e:
60
  return str(e)
61
 
62
+ # JavaScript to copy text to clipboard
63
+ copy_js = """
64
+ function copyText() {
65
+ const outputText = document.querySelector('textarea').value;
66
+ navigator.clipboard.writeText(outputText).then(function() {
67
+ alert('Text copied to clipboard');
68
+ }, function(err) {
69
+ alert('Failed to copy text: ', err);
70
+ });
71
+ }
72
+ """
73
+
74
+ # Gradio interface
75
+ with gr.Blocks() as iface:
76
+ input_text = gr.Textbox(lines=2, placeholder="Enter text here...")
77
+ output_text = gr.Textbox(lines=5, interactive=False)
78
+ copy_button = gr.Button("Copy Output Text")
79
+
80
+ def copy_to_clipboard():
81
+ return gr.update(_js="copyText()")
82
+
83
+ input_text.change(generate, inputs=input_text, outputs=output_text)
84
+ copy_button.click(copy_to_clipboard)
85
+
86
+ gr.Markdown(f"<script>{copy_js}</script>")
87
+
88
+ gr.Markdown("<h1>Chuunibyou Text Generator V1.02</h1>")
89
+ gr.Markdown("Transform text into an elaborate and formal style with a nobleman tone.")
90
 
91
  if __name__ == "__main__":
92
+ iface.launch()