Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,36 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
|
|
|
| 3 |
|
| 4 |
-
# Load
|
| 5 |
generator = pipeline("text-generation", model="google/flan-t5-base")
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
def generate_test_cases(user_story):
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
iface = gr.Interface(
|
| 16 |
fn=generate_test_cases,
|
| 17 |
inputs=gr.Textbox(lines=5, placeholder="Enter your user story here..."),
|
|
@@ -20,6 +39,5 @@ iface = gr.Interface(
|
|
| 20 |
description="Enter a user story and get structured test cases in JSON format.",
|
| 21 |
)
|
| 22 |
|
| 23 |
-
|
| 24 |
if __name__ == "__main__":
|
| 25 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
+
import signal
|
| 4 |
|
| 5 |
+
# Load model
|
| 6 |
generator = pipeline("text-generation", model="google/flan-t5-base")
|
| 7 |
|
| 8 |
+
# Function to handle timeouts
|
| 9 |
+
class TimeoutException(Exception):
|
| 10 |
+
pass
|
| 11 |
+
|
| 12 |
+
def timeout_handler(signum, frame):
|
| 13 |
+
raise TimeoutException("Processing took too long. Try a simpler input.")
|
| 14 |
+
|
| 15 |
+
signal.signal(signal.SIGALRM, timeout_handler)
|
| 16 |
+
|
| 17 |
def generate_test_cases(user_story):
|
| 18 |
+
try:
|
| 19 |
+
# Set a 3-minute timeout
|
| 20 |
+
signal.alarm(120)
|
| 21 |
+
|
| 22 |
+
prompt = f"Generate structured test cases in JSON format from this user story: {user_story}"
|
| 23 |
+
output = generator(prompt, max_length=300, do_sample=True)[0]["generated_text"]
|
| 24 |
|
| 25 |
+
# Disable the alarm if processing is successful
|
| 26 |
+
signal.alarm(0)
|
| 27 |
|
| 28 |
+
return output
|
| 29 |
+
|
| 30 |
+
except TimeoutException:
|
| 31 |
+
return "Processing timed out. Please try again with a simpler input."
|
| 32 |
+
|
| 33 |
+
# Create Gradio interface
|
| 34 |
iface = gr.Interface(
|
| 35 |
fn=generate_test_cases,
|
| 36 |
inputs=gr.Textbox(lines=5, placeholder="Enter your user story here..."),
|
|
|
|
| 39 |
description="Enter a user story and get structured test cases in JSON format.",
|
| 40 |
)
|
| 41 |
|
|
|
|
| 42 |
if __name__ == "__main__":
|
| 43 |
iface.launch()
|