Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,11 +2,10 @@ import google.generativeai as genai
|
|
2 |
import gradio as gr
|
3 |
import numpy as np
|
4 |
import PIL.Image
|
5 |
-
import io
|
6 |
|
7 |
genai.configure(api_key="AIzaSyAj-b3sO_wUguMdpXWScxKzMHxb8C5cels")
|
8 |
|
9 |
-
def ImageChat(image
|
10 |
# Check image file and convert to a PIL Image object
|
11 |
if isinstance(image, np.ndarray):
|
12 |
img = PIL.Image.fromarray(image)
|
@@ -50,17 +49,23 @@ def ImageChat(image, prompt):
|
|
50 |
return "No valid response received. The response might have been blocked."
|
51 |
|
52 |
# Apply rich formatting to the response
|
53 |
-
formatted_response = response.text
|
|
|
|
|
|
|
|
|
54 |
return formatted_response
|
55 |
except ValueError as e:
|
56 |
return f"Error in generating response: {e}"
|
57 |
|
58 |
app = gr.Interface(
|
59 |
fn=ImageChat,
|
60 |
-
inputs=[gr.Image(label="Image")
|
61 |
outputs=gr.Text(label="Response"),
|
62 |
title="Image Chat",
|
63 |
-
theme=gr.themes.Soft()
|
|
|
64 |
)
|
65 |
|
66 |
-
|
|
|
|
2 |
import gradio as gr
|
3 |
import numpy as np
|
4 |
import PIL.Image
|
|
|
5 |
|
6 |
genai.configure(api_key="AIzaSyAj-b3sO_wUguMdpXWScxKzMHxb8C5cels")
|
7 |
|
8 |
+
def ImageChat(image):
|
9 |
# Check image file and convert to a PIL Image object
|
10 |
if isinstance(image, np.ndarray):
|
11 |
img = PIL.Image.fromarray(image)
|
|
|
49 |
return "No valid response received. The response might have been blocked."
|
50 |
|
51 |
# Apply rich formatting to the response
|
52 |
+
formatted_response = response.text
|
53 |
+
for title in ["Trend Analysis", "Price Action", "Entry Point", "Exit Point", "Hold Conditions", "Risk Management", "Timeframe", "Profit Potential"]:
|
54 |
+
formatted_response = formatted_response.replace(title, f"**{title.upper()}**")
|
55 |
+
formatted_response = formatted_response.replace('\n', '\n\n')
|
56 |
+
formatted_response = re.sub(r"(\d+\.?\d*)", r"**\1**", formatted_response)
|
57 |
return formatted_response
|
58 |
except ValueError as e:
|
59 |
return f"Error in generating response: {e}"
|
60 |
|
61 |
app = gr.Interface(
|
62 |
fn=ImageChat,
|
63 |
+
inputs=[gr.Image(label="Image")],
|
64 |
outputs=gr.Text(label="Response"),
|
65 |
title="Image Chat",
|
66 |
+
theme=gr.themes.Soft(),
|
67 |
+
live=False
|
68 |
)
|
69 |
|
70 |
+
# Add a new button under the image frame named 'Analyze'
|
71 |
+
app.launch(button_text="Analyze", bg_color="#26de81", text_color="#ffffff")
|