ysharma HF staff commited on
Commit
44f3e2d
1 Parent(s): bb17c18

updates to app.py

Browse files

Changes interface to blocks api.
- Additional changes to include `gr.Chatbot` to be able to use `placeholder`
- Added multimodal textbox to be able to use multimodal examples correctly

Files changed (1) hide show
  1. app.py +18 -4
app.py CHANGED
@@ -9,6 +9,16 @@ from transformers import TextIteratorStreamer
9
 
10
  import spaces
11
 
 
 
 
 
 
 
 
 
 
 
12
  model_id = "xtuner/llava-llama-3-8b-v1_1-transformers"
13
 
14
  processor = AutoProcessor.from_pretrained(model_id)
@@ -76,16 +86,20 @@ def bot_streaming(message, history):
76
  yield generated_text_without_prompt
77
 
78
 
79
- demo = gr.ChatInterface(
 
 
 
80
  fn=bot_streaming,
81
- fill_height=False,
82
  title="LLaVA Llama-3-8B",
83
  examples=[{"text": "What is on the flower?", "files": ["./bee.jpg"]},
84
  {"text": "How to make this pastry?", "files": ["./baklava.png"]}],
85
  description="Try [LLaVA Llama-3-8B](https://huggingface.co/xtuner/llava-llama-3-8b-v1_1-transformers). Upload an image and start chatting about it, or simply try one of the examples below. If you don't upload an image, you will receive an error.",
86
  stop_btn="Stop Generation",
87
- multimodal=True
88
- )
 
 
89
 
90
  demo.queue(api_open=False)
91
  demo.launch(show_api=False, share=False)
 
9
 
10
  import spaces
11
 
12
+
13
+ PLACEHOLDER = """
14
+ <div style="padding: 30px; text-align: center; display: flex; flex-direction: column; align-items: center;">
15
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/64ccdc322e592905f922a06e/DDIW0kbWmdOQWwy4XMhwX.png" style="width: 80%; max-width: 550px; height: auto; opacity: 0.55; ">
16
+ <h1 style="font-size: 28px; margin-bottom: 2px; opacity: 0.55;">LLaVA-Llama-3-8B</h1>
17
+ <p style="font-size: 18px; margin-bottom: 2px; opacity: 0.65;">Llava-Llama-3-8b is a LLaVA model fine-tuned from Meta-Llama-3-8B-Instruct and CLIP-ViT-Large-patch14-336 with ShareGPT4V-PT and InternVL-SFT by XTuner</p>
18
+ </div>
19
+ """
20
+
21
+
22
  model_id = "xtuner/llava-llama-3-8b-v1_1-transformers"
23
 
24
  processor = AutoProcessor.from_pretrained(model_id)
 
86
  yield generated_text_without_prompt
87
 
88
 
89
+ chatbot=gr.Chatbot(placeholder=PLACEHOLDER,scale=1)
90
+ chat_input = gr.MultimodalTextbox(interactive=True, file_types=["image"], placeholder="Enter message or upload file...", show_label=False)
91
+ with gr.Blocks(fill_height=True, ) as demo:
92
+ gr.ChatInterface(
93
  fn=bot_streaming,
 
94
  title="LLaVA Llama-3-8B",
95
  examples=[{"text": "What is on the flower?", "files": ["./bee.jpg"]},
96
  {"text": "How to make this pastry?", "files": ["./baklava.png"]}],
97
  description="Try [LLaVA Llama-3-8B](https://huggingface.co/xtuner/llava-llama-3-8b-v1_1-transformers). Upload an image and start chatting about it, or simply try one of the examples below. If you don't upload an image, you will receive an error.",
98
  stop_btn="Stop Generation",
99
+ multimodal=True,
100
+ textbox=chat_input,
101
+ chatbot=chatbot,
102
+ )
103
 
104
  demo.queue(api_open=False)
105
  demo.launch(show_api=False, share=False)