Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import base64
|
|
| 5 |
from io import BytesIO
|
| 6 |
from PIL import Image
|
| 7 |
import numpy as np
|
|
|
|
| 8 |
|
| 9 |
# Initialize the Together client
|
| 10 |
api_key = os.environ.get('TOGETHER_API_KEY')
|
|
@@ -58,13 +59,17 @@ def generate_gradio_app(image):
|
|
| 58 |
for chunk in stream:
|
| 59 |
if chunk.choices[0].delta.content is not None:
|
| 60 |
generated_text += chunk.choices[0].delta.content
|
| 61 |
-
yield
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
return generated_text
|
| 64 |
|
| 65 |
except Exception as e:
|
| 66 |
error_message = str(e)
|
| 67 |
-
|
|
|
|
| 68 |
|
| 69 |
with gr.Blocks() as demo:
|
| 70 |
gr.Markdown("# Analyze wireframe and suggest Gradio app layout")
|
|
@@ -84,4 +89,5 @@ with gr.Blocks() as demo:
|
|
| 84 |
outputs=[text_output]
|
| 85 |
)
|
| 86 |
|
| 87 |
-
|
|
|
|
|
|
| 5 |
from io import BytesIO
|
| 6 |
from PIL import Image
|
| 7 |
import numpy as np
|
| 8 |
+
import traceback
|
| 9 |
|
| 10 |
# Initialize the Together client
|
| 11 |
api_key = os.environ.get('TOGETHER_API_KEY')
|
|
|
|
| 59 |
for chunk in stream:
|
| 60 |
if chunk.choices[0].delta.content is not None:
|
| 61 |
generated_text += chunk.choices[0].delta.content
|
| 62 |
+
yield f"Generating... (Current length: {len(generated_text)} characters)\n\n{generated_text}"
|
| 63 |
+
|
| 64 |
+
if not generated_text:
|
| 65 |
+
return "Error: No response generated from the model. Please try again."
|
| 66 |
|
| 67 |
return generated_text
|
| 68 |
|
| 69 |
except Exception as e:
|
| 70 |
error_message = str(e)
|
| 71 |
+
stack_trace = traceback.format_exc()
|
| 72 |
+
return f"An error occurred: {error_message}\n\nStack trace:\n{stack_trace}\n\nPlease try again or check your API key and connection."
|
| 73 |
|
| 74 |
with gr.Blocks() as demo:
|
| 75 |
gr.Markdown("# Analyze wireframe and suggest Gradio app layout")
|
|
|
|
| 89 |
outputs=[text_output]
|
| 90 |
)
|
| 91 |
|
| 92 |
+
if __name__ == "__main__":
|
| 93 |
+
demo.launch(debug=True)
|