Spaces:
Restarting
Restarting
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ from huggingface_hub import InferenceClient
|
|
5 |
import gradio as gr
|
6 |
from pydantic import BaseModel, Field
|
7 |
from typing import Optional, Literal
|
|
|
8 |
|
9 |
class PromptInput(BaseModel):
|
10 |
text: str = Field(..., description="The initial prompt text")
|
@@ -19,7 +20,7 @@ class RefinementOutput(BaseModel):
|
|
19 |
|
20 |
class PromptRefiner:
|
21 |
def __init__(self, api_token: str):
|
22 |
-
self.client = InferenceClient(token=api_token)
|
23 |
|
24 |
def refine_prompt(self, prompt_input: PromptInput) -> RefinementOutput:
|
25 |
if prompt_input.meta_prompt_choice == "morphosis":
|
@@ -55,12 +56,18 @@ class PromptRefiner:
|
|
55 |
response_content = response.choices[0].message.content.strip()
|
56 |
except HfHubHTTPError as e:
|
57 |
return (
|
58 |
-
"Error: Model timeout. Please
|
59 |
"",
|
60 |
"The selected model is currently experiencing high traffic.",
|
61 |
{}
|
62 |
)
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
try:
|
65 |
json_match = re.search(r'<json>\s*(.*?)\s*</json>', response_content, re.DOTALL)
|
66 |
if json_match:
|
|
|
5 |
import gradio as gr
|
6 |
from pydantic import BaseModel, Field
|
7 |
from typing import Optional, Literal
|
8 |
+
from huggingface_hub.utils._errors import HfHubHTTPError
|
9 |
|
10 |
class PromptInput(BaseModel):
|
11 |
text: str = Field(..., description="The initial prompt text")
|
|
|
20 |
|
21 |
class PromptRefiner:
|
22 |
def __init__(self, api_token: str):
|
23 |
+
self.client = InferenceClient(token=api_token,timeout=300)
|
24 |
|
25 |
def refine_prompt(self, prompt_input: PromptInput) -> RefinementOutput:
|
26 |
if prompt_input.meta_prompt_choice == "morphosis":
|
|
|
56 |
response_content = response.choices[0].message.content.strip()
|
57 |
except HfHubHTTPError as e:
|
58 |
return (
|
59 |
+
"Error: Model timeout. Please again later.",
|
60 |
"",
|
61 |
"The selected model is currently experiencing high traffic.",
|
62 |
{}
|
63 |
)
|
64 |
+
except Exception as e:
|
65 |
+
return (
|
66 |
+
f"Error: {str(e)}",
|
67 |
+
"",
|
68 |
+
"An unexpected error occurred.",
|
69 |
+
{}
|
70 |
+
)
|
71 |
try:
|
72 |
json_match = re.search(r'<json>\s*(.*?)\s*</json>', response_content, re.DOTALL)
|
73 |
if json_match:
|