Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import os
|
2 |
import base64
|
3 |
import gradio as gr
|
4 |
-
from gradio_client import Client
|
5 |
import json
|
6 |
|
7 |
MODEL_NAME = "QWEN"
|
@@ -50,16 +50,9 @@ def process_text(text_input, unit):
|
|
50 |
system=f"You are a experienced {unit} doctor AI assistant." + SYS_PROMPT,
|
51 |
api_name="/model_chat"
|
52 |
)
|
53 |
-
|
54 |
-
response = job.result()
|
55 |
print(response)
|
56 |
-
return response[1][0]
|
57 |
-
|
58 |
-
def encode_image_to_base64(image_input):
|
59 |
-
buffered = io.BytesIO()
|
60 |
-
image_input.save(buffered, format="JPEG")
|
61 |
-
img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
|
62 |
-
return img_str
|
63 |
|
64 |
def process_image(image_input, unit):
|
65 |
if image_input is not None:
|
@@ -67,21 +60,19 @@ def process_image(image_input, unit):
|
|
67 |
#with open(image_input, "rb") as f:
|
68 |
# base64_image = base64.b64encode(f.read()).decode("utf-8")
|
69 |
client = Client(client_vl)
|
70 |
-
# base64_image = encode_image_to_base64(image_input)
|
71 |
prompt = f" You are a experienced {unit} doctor AI assistant." + SYS_PROMPT + "Help me understand what is in this picture and analysis."
|
72 |
-
client.predict(
|
73 |
-
|
74 |
-
image_input,
|
75 |
fn_index=5
|
76 |
)
|
|
|
77 |
response = client.predict(
|
78 |
-
|
79 |
-
prompt,
|
80 |
fn_index=0
|
81 |
)
|
82 |
print(response)
|
83 |
-
|
84 |
-
|
85 |
def main(text_input="", image_input=None, unit=""):
|
86 |
if text_input and image_input is None:
|
87 |
return process_text(text_input,unit)
|
|
|
1 |
import os
|
2 |
import base64
|
3 |
import gradio as gr
|
4 |
+
from gradio_client import Client, file
|
5 |
import json
|
6 |
|
7 |
MODEL_NAME = "QWEN"
|
|
|
50 |
system=f"You are a experienced {unit} doctor AI assistant." + SYS_PROMPT,
|
51 |
api_name="/model_chat"
|
52 |
)
|
53 |
+
response = job.outputs
|
|
|
54 |
print(response)
|
55 |
+
return response[1][0][0]
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
def process_image(image_input, unit):
|
58 |
if image_input is not None:
|
|
|
60 |
#with open(image_input, "rb") as f:
|
61 |
# base64_image = base64.b64encode(f.read()).decode("utf-8")
|
62 |
client = Client(client_vl)
|
|
|
63 |
prompt = f" You are a experienced {unit} doctor AI assistant." + SYS_PROMPT + "Help me understand what is in this picture and analysis."
|
64 |
+
res = client.predict(
|
65 |
+
file = file(image_input),
|
|
|
66 |
fn_index=5
|
67 |
)
|
68 |
+
print(res)
|
69 |
response = client.predict(
|
70 |
+
text = prompt,
|
|
|
71 |
fn_index=0
|
72 |
)
|
73 |
print(response)
|
74 |
+
return response[1][0][0]
|
75 |
+
|
76 |
def main(text_input="", image_input=None, unit=""):
|
77 |
if text_input and image_input is None:
|
78 |
return process_text(text_input,unit)
|