s3nh commited on
Commit
5296c4e
1 Parent(s): 8d28c09

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +107 -0
app.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import gradio as gr
3
+ from fastapi import FastAPI
4
+
5
+
6
+ import os
7
+ from PIL import Image
8
+
9
+ import tempfile
10
+ from transformers import TextStreamer
11
+ from utils import title_markdown
12
+ from utils import block_css
13
+ from utils import tos_markdown
14
+ from utils import learn_more_markdown
15
+
16
+ #app = FastAPI()
17
+
18
+ textbox = gr.Textbox(
19
+ show_label = False, placeholder = "Enter text and press ENTER", container = False
20
+ )
21
+
22
+ with gr.Blocks(title = '' ) as demo:
23
+ gr.Markdown(title_markdown)
24
+
25
+ with gr.Blocks(title='MoE-LLaVA🚀')) as demo:
26
+ gr.Markdown(title_markdown)
27
+ state = gr.State()
28
+ state_ = gr.State()
29
+ first_run = gr.State()
30
+ images_tensor = gr.State()
31
+
32
+ with gr.Row():
33
+ with gr.Column(scale=3):
34
+ image1 = gr.Image(label="Input Document", type="filepath")
35
+
36
+ cur_dir = os.path.dirname(os.path.abspath(__file__))
37
+ print(cur_dir)
38
+ gr.Examples(
39
+ examples=[
40
+ [
41
+ f"demo.jfif",
42
+ "What is unusual about this image?",
43
+ ],
44
+ [
45
+ f"demo.jfif",
46
+ "What are the things I should be cautious about when I visit here?",
47
+ ],
48
+ [
49
+ f"demo.jfif",
50
+ "If there are factual errors in the questions, point it out; if not, proceed answering the question. What’s happening in the desert?",
51
+ ],
52
+ [
53
+ f"demo.jfif",
54
+ "What is the title of this book?",
55
+ ],
56
+ [
57
+ f"demo.jfif",
58
+ "What type of food is the girl holding?",
59
+ ],
60
+ [
61
+ f"demo.jfif",
62
+ "What color is the train?",
63
+ ],
64
+ [
65
+ f"demo.jfif",
66
+ "What is the girl looking at?",
67
+ ],
68
+ [
69
+ f"demo.jfif",
70
+ "What might be the reason for the dog's aggressive behavior?",
71
+ ],
72
+ ],
73
+ inputs=[image1, textbox],
74
+ )
75
+
76
+ # with gr.Column(scale=7):
77
+ # #chatbot = gr.Chatbot(label="MoE-LLaVA", bubble_full_width=True).style(height=750)
78
+ # with gr.Row():
79
+ # with gr.Column(scale=8):
80
+ # textbox.render()
81
+ # with gr.Column(scale=1, min_width=50):
82
+ # submit_btn = gr.Button(
83
+ # value="Send", variant="primary", interactive=True
84
+ # )
85
+ # with gr.Row(elem_id="buttons") as button_row:
86
+ # upvote_btn = gr.Button(value="👍 Upvote", interactive=True)
87
+ # downvote_btn = gr.Button(value="👎 Downvote", interactive=True)
88
+ # flag_btn = gr.Button(value="⚠️ Flag", interactive=True)
89
+ # # stop_btn = gr.Button(value="⏹️ Stop Generation", interactive=False)
90
+ # regenerate_btn = gr.Button(value="🔄 Regenerate", interactive=True)
91
+ # clear_btn = gr.Button(value="🗑️ Clear history", interactive=True)
92
+
93
+ # gr.Markdown(tos_markdown)
94
+ # gr.Markdown(learn_more_markdown)
95
+
96
+ # submit_btn.click(generate, [image1, textbox, first_run, state, state_, images_tensor],
97
+ # [state, state_, chatbot, first_run, textbox, images_tensor, image1])
98
+
99
+ # regenerate_btn.click(regenerate, [state, state_], [state, state_, chatbot, first_run]).then(
100
+ # generate, [image1, textbox, first_run, state, state_, images_tensor],
101
+ # [state, state_, chatbot, first_run, textbox, images_tensor, image1])
102
+
103
+ # clear_btn.click(clear_history, [state, state_],
104
+ # [image1, textbox, first_run, state, state_, chatbot, images_tensor])
105
+
106
+ # app = gr.mount_gradio_app(app, demo, path="/")
107
+ demo.launch()