Spaces:
Sleeping
Sleeping
Nightwalkx
commited on
Commit
·
cce64df
1
Parent(s):
630442c
update app
Browse files
app.py
CHANGED
|
@@ -11,20 +11,20 @@ model_id = "rogerxi/llava-finetune-test"
|
|
| 11 |
pipe = pipeline("image-text-to-text", model=model_id, model_kwargs={"quantization_config": quantization_config})
|
| 12 |
|
| 13 |
def update_conversation(new_message, history, image):
|
| 14 |
-
|
| 15 |
if image is None:
|
| 16 |
return "Please upload an image first using the widget on the left"
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
for i in range(len(history)):
|
| 21 |
-
prompt += history[i][0] + '\nASSISTANT: ' + history[i][1] + "\nUSER: "
|
| 22 |
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
outputs = pipe(
|
|
|
|
| 26 |
|
| 27 |
-
return outputs[len(prompt) - 6:]
|
| 28 |
|
| 29 |
with gr.Blocks() as demo:
|
| 30 |
|
|
@@ -35,4 +35,4 @@ with gr.Blocks() as demo:
|
|
| 35 |
update_conversation, additional_inputs=[image]
|
| 36 |
)
|
| 37 |
|
| 38 |
-
demo.launch(
|
|
|
|
| 11 |
pipe = pipeline("image-text-to-text", model=model_id, model_kwargs={"quantization_config": quantization_config})
|
| 12 |
|
| 13 |
def update_conversation(new_message, history, image):
|
|
|
|
| 14 |
if image is None:
|
| 15 |
return "Please upload an image first using the widget on the left"
|
| 16 |
|
| 17 |
+
messages = [{"role": "user", "content": "<image>"}]
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
for user_text, assistant_text in history:
|
| 20 |
+
messages.append({"role": "user", "content": user_text})
|
| 21 |
+
messages.append({"role": "assistant", "content": assistant_text})
|
| 22 |
+
|
| 23 |
+
messages.append({"role": "user", "content": new_message})
|
| 24 |
|
| 25 |
+
outputs = pipe(messages=messages, generate_kwargs={"max_new_tokens": 200})[0]['generated_text']
|
| 26 |
+
return outputs
|
| 27 |
|
|
|
|
| 28 |
|
| 29 |
with gr.Blocks() as demo:
|
| 30 |
|
|
|
|
| 35 |
update_conversation, additional_inputs=[image]
|
| 36 |
)
|
| 37 |
|
| 38 |
+
demo.launch()
|