Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -84,50 +84,29 @@ def process_speech(input_language, audio_input):
|
|
84 |
|
85 |
|
86 |
|
87 |
-
def process_image(image)
|
|
|
88 |
img_name = f"{np.random.randint(0, 100)}.jpg"
|
89 |
PIL.Image.fromarray(image.astype('uint8'), 'RGB').save(img_name)
|
90 |
-
image = open(img_name, "rb").read()
|
91 |
-
base64_image = base64_image = base64.b64encode(image).decode('utf-8')
|
92 |
-
openai_api_key = os.getenv('OPENAI_API_KEY')
|
93 |
-
# oai_org = os.getenv('OAI_ORG')
|
94 |
-
|
95 |
-
headers = {
|
96 |
-
"Content-Type": "application/json",
|
97 |
-
"Authorization": f"Bearer {openai_api_key}"
|
98 |
-
}
|
99 |
|
|
|
100 |
payload = {
|
101 |
-
"
|
102 |
-
|
103 |
-
|
104 |
-
"role": "user",
|
105 |
-
"content": [
|
106 |
-
{
|
107 |
-
"type": "text",
|
108 |
-
"text": "You are clinical consultant discussion training cases with students at TonicUniversity. Assess and describe the photo in minute detail. Explain why each area or item in the photograph would be inappropriate to describe if required. Pay attention to anatomy, symptoms and remedies. Propose a course of action based on your assessment. Exclude any other commentary:"
|
109 |
-
},
|
110 |
-
{
|
111 |
-
"type": "image_url",
|
112 |
-
"image_url": {
|
113 |
-
"url": f"data:image/jpeg;base64,{base64_image}"
|
114 |
-
}
|
115 |
-
}
|
116 |
-
]
|
117 |
-
}
|
118 |
],
|
119 |
-
"
|
120 |
}
|
121 |
|
122 |
-
|
|
|
123 |
|
124 |
-
try
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
return f"{e}"
|
131 |
|
132 |
|
133 |
def query_vectara(text):
|
|
|
84 |
|
85 |
|
86 |
|
87 |
+
def process_image(image):
|
88 |
+
# Save the image to a file
|
89 |
img_name = f"{np.random.randint(0, 100)}.jpg"
|
90 |
PIL.Image.fromarray(image.astype('uint8'), 'RGB').save(img_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
+
# Prepare the payload for the Gradio client
|
93 |
payload = {
|
94 |
+
"data": [
|
95 |
+
img_name, # File path of the saved image
|
96 |
+
"Hello!!" # Example text, replace with relevant text if needed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
],
|
98 |
+
"api_name": "/http_bot"
|
99 |
}
|
100 |
|
101 |
+
# Initialize the Gradio client
|
102 |
+
client = Client("https://teamtonic-otterhd-demo.hf.space/--replicas/rcng4/")
|
103 |
|
104 |
+
try:
|
105 |
+
# Send the request to the Gradio client
|
106 |
+
result = client.predict(payload)
|
107 |
+
return result
|
108 |
+
except Exception as e:
|
109 |
+
return f"Error: {e}"
|
|
|
110 |
|
111 |
|
112 |
def query_vectara(text):
|