Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,11 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
-
import json
|
4 |
-
|
5 |
import os
|
6 |
|
7 |
# WARNING: It is not recommended to hardcode sensitive data like API tokens in code.
|
8 |
# Consider using environment variables or other secure methods for production applications.
|
9 |
API_URL = "https://deployment.datasaur.ai/api/deployment/8/2717/chat/completions"
|
10 |
-
API_TOKEN = os.
|
11 |
|
12 |
def magic_function(input_text):
|
13 |
"""
|
@@ -38,18 +36,29 @@ def magic_function(input_text):
|
|
38 |
# Handle cases where response is not valid JSON or structure is unexpected
|
39 |
return f"Error processing API response: {response.text}"
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
with gr.Blocks() as demo:
|
43 |
gr.Markdown("# Memo Improvement Workflow")
|
44 |
with gr.Row():
|
45 |
-
|
|
|
|
|
46 |
with gr.Column(scale=1):
|
47 |
magic_button = gr.Button("Magic Button")
|
48 |
|
49 |
magic_button.click(
|
50 |
-
fn=
|
51 |
inputs=text_area,
|
52 |
-
outputs=text_area
|
53 |
)
|
54 |
|
55 |
if __name__ == "__main__":
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
|
|
|
|
3 |
import os
|
4 |
|
5 |
# WARNING: It is not recommended to hardcode sensitive data like API tokens in code.
|
6 |
# Consider using environment variables or other secure methods for production applications.
|
7 |
API_URL = "https://deployment.datasaur.ai/api/deployment/8/2717/chat/completions"
|
8 |
+
API_TOKEN = os.getenv("DATASAUR_API_TOKEN")
|
9 |
|
10 |
def magic_function(input_text):
|
11 |
"""
|
|
|
36 |
# Handle cases where response is not valid JSON or structure is unexpected
|
37 |
return f"Error processing API response: {response.text}"
|
38 |
|
39 |
+
def handle_magic_click(current_text):
|
40 |
+
"""
|
41 |
+
When the magic button is clicked, this function gets the improved text,
|
42 |
+
and returns the new and previous text to update the UI.
|
43 |
+
It also makes the "Previous Text" box visible.
|
44 |
+
"""
|
45 |
+
improved_text = magic_function(current_text)
|
46 |
+
return improved_text, current_text, gr.update(visible=True)
|
47 |
+
|
48 |
|
49 |
with gr.Blocks() as demo:
|
50 |
gr.Markdown("# Memo Improvement Workflow")
|
51 |
with gr.Row():
|
52 |
+
with gr.Column(scale=4):
|
53 |
+
text_area = gr.Textbox(label="Your Text", lines=20)
|
54 |
+
previous_text_area = gr.Textbox(label="Previous Text", lines=20, visible=False)
|
55 |
with gr.Column(scale=1):
|
56 |
magic_button = gr.Button("Magic Button")
|
57 |
|
58 |
magic_button.click(
|
59 |
+
fn=handle_magic_click,
|
60 |
inputs=text_area,
|
61 |
+
outputs=[text_area, previous_text_area, previous_text_area]
|
62 |
)
|
63 |
|
64 |
if __name__ == "__main__":
|