Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
import requests
|
| 2 |
-
import time
|
| 3 |
import os
|
| 4 |
|
| 5 |
import gradio as gr
|
|
@@ -23,8 +22,6 @@ EXAMPLE_QUERIES = [
|
|
| 23 |
|
| 24 |
|
| 25 |
def make_request(query):
|
| 26 |
-
start_time = time.time()
|
| 27 |
-
|
| 28 |
try:
|
| 29 |
# Replace with your actual API endpoint
|
| 30 |
if "rewrite: " not in query:
|
|
@@ -35,10 +32,7 @@ def make_request(query):
|
|
| 35 |
except requests.exceptions.RequestException as e:
|
| 36 |
result = f"Error: {str(e)}"
|
| 37 |
|
| 38 |
-
|
| 39 |
-
processing_time = round(end_time - start_time, 2)
|
| 40 |
-
|
| 41 |
-
return result, f"Response Time: {processing_time} seconds"
|
| 42 |
|
| 43 |
|
| 44 |
# Create the Gradio interface
|
|
@@ -65,13 +59,12 @@ with gr.Blocks() as app:
|
|
| 65 |
|
| 66 |
with gr.Row():
|
| 67 |
response_output = gr.Textbox(label="Rewritten Text", lines=5, interactive=False)
|
| 68 |
-
time_label = gr.Label(label="Processing Time")
|
| 69 |
|
| 70 |
# Add examples section
|
| 71 |
gr.Examples(
|
| 72 |
examples=EXAMPLE_QUERIES,
|
| 73 |
inputs=query_input,
|
| 74 |
-
outputs=[response_output
|
| 75 |
fn=make_request,
|
| 76 |
cache_examples=True,
|
| 77 |
label="Example Queries",
|
|
@@ -80,18 +73,14 @@ with gr.Blocks() as app:
|
|
| 80 |
# Clear button functionality
|
| 81 |
clear_btn.click(
|
| 82 |
lambda: ("", "", ""), # Clear input # Clear output # Clear time label
|
| 83 |
-
outputs=[query_input, response_output
|
| 84 |
)
|
| 85 |
|
| 86 |
# Submit button click event
|
| 87 |
-
submit_btn.click(
|
| 88 |
-
fn=make_request, inputs=[query_input], outputs=[response_output, time_label]
|
| 89 |
-
)
|
| 90 |
|
| 91 |
# Add keyboard shortcut for submission
|
| 92 |
-
query_input.submit(
|
| 93 |
-
fn=make_request, inputs=[query_input], outputs=[response_output, time_label]
|
| 94 |
-
)
|
| 95 |
|
| 96 |
# Launch the app
|
| 97 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import requests
|
|
|
|
| 2 |
import os
|
| 3 |
|
| 4 |
import gradio as gr
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
def make_request(query):
|
|
|
|
|
|
|
| 25 |
try:
|
| 26 |
# Replace with your actual API endpoint
|
| 27 |
if "rewrite: " not in query:
|
|
|
|
| 32 |
except requests.exceptions.RequestException as e:
|
| 33 |
result = f"Error: {str(e)}"
|
| 34 |
|
| 35 |
+
return result
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
|
| 38 |
# Create the Gradio interface
|
|
|
|
| 59 |
|
| 60 |
with gr.Row():
|
| 61 |
response_output = gr.Textbox(label="Rewritten Text", lines=5, interactive=False)
|
|
|
|
| 62 |
|
| 63 |
# Add examples section
|
| 64 |
gr.Examples(
|
| 65 |
examples=EXAMPLE_QUERIES,
|
| 66 |
inputs=query_input,
|
| 67 |
+
outputs=[response_output],
|
| 68 |
fn=make_request,
|
| 69 |
cache_examples=True,
|
| 70 |
label="Example Queries",
|
|
|
|
| 73 |
# Clear button functionality
|
| 74 |
clear_btn.click(
|
| 75 |
lambda: ("", "", ""), # Clear input # Clear output # Clear time label
|
| 76 |
+
outputs=[query_input, response_output],
|
| 77 |
)
|
| 78 |
|
| 79 |
# Submit button click event
|
| 80 |
+
submit_btn.click(fn=make_request, inputs=[query_input], outputs=[response_output])
|
|
|
|
|
|
|
| 81 |
|
| 82 |
# Add keyboard shortcut for submission
|
| 83 |
+
query_input.submit(fn=make_request, inputs=[query_input], outputs=[response_output])
|
|
|
|
|
|
|
| 84 |
|
| 85 |
# Launch the app
|
| 86 |
if __name__ == "__main__":
|