SMeyersMrOvkill commited on
Commit
4b2e1d6
1 Parent(s): 40b8949
Files changed (2) hide show
  1. app.py +20 -7
  2. requirements.txt +1 -0
app.py CHANGED
@@ -9,7 +9,7 @@ from PIL import Image
9
  from typing import Union
10
  import os
11
 
12
- device = "cuda"
13
  print(f"Using {device}" if device != "cpu" else "Using CPU")
14
 
15
  def _load_model():
@@ -32,6 +32,8 @@ class MoonDream():
32
  yield res
33
  return
34
 
 
 
35
  def _respond_one(question, img):
36
  txt = ""
37
  yield (txt := txt + MoonDream()(question, [img]))
@@ -97,13 +99,21 @@ def xform_image_description(img, inst):
97
  res = tog.completions.create(prompt=prompt, model="meta-llama/Meta-Llama-3-70B", stop=["```"], max_tokens=1024)
98
  return res.choices[0].text[len(prompt):].split("```")[0]
99
 
100
- with gr.Blocks() as demo:
101
- with gr.Row(visible=True):
 
 
 
102
  with gr.Column():
103
- img = gr.Image(label="images", type='pil')
104
  with gr.Column():
105
- otpt = gr.Textbox(label="output", lines=3, interactive=True)
106
- btn = gr.Button("submit")
 
 
 
 
 
107
  with gr.Row():
108
  with gr.Column():
109
  im1 = gr.Image(label="image 1", type='pil')
@@ -131,4 +141,7 @@ with gr.Blocks() as demo:
131
  btn.click(dual_images, inputs=[img], outputs=[otpt])
132
  btn_scd.click(merge_descriptions_to_prompt, inputs=[minst, otp2, otp3], outputs=[otp4])
133
 
134
- demo.launch(debug=True, share=True)
 
 
 
 
9
  from typing import Union
10
  import os
11
 
12
+ device = "cuda" if torch.cuda.is_available() else "cpu"
13
  print(f"Using {device}" if device != "cpu" else "Using CPU")
14
 
15
  def _load_model():
 
32
  yield res
33
  return
34
 
35
+ md = MoonDream()
36
+
37
  def _respond_one(question, img):
38
  txt = ""
39
  yield (txt := txt + MoonDream()(question, [img]))
 
99
  res = tog.completions.create(prompt=prompt, model="meta-llama/Meta-Llama-3-70B", stop=["```"], max_tokens=1024)
100
  return res.choices[0].text[len(prompt):].split("```")[0]
101
 
102
+ def simple_desc(img, prompt):
103
+ return md(img, prompt)
104
+
105
+ with gr.Blocks() as if_simple_description:
106
+ with gr.Row():
107
  with gr.Column():
108
+ simple_img = gr.Image(type="pil")
109
  with gr.Column():
110
+ simple_text = gr.Textbox(label="prompt ( Shift+Enter sends )")
111
+ simple_btn = gr.Button("Prompt & Image 2 Text")
112
+ simple_btn.click(simple_desc, inputs=[simple_img, simple_desc], outputs=[simple_desc])
113
+
114
+ """
115
+ with gr.Blocks() as demo:
116
+
117
  with gr.Row():
118
  with gr.Column():
119
  im1 = gr.Image(label="image 1", type='pil')
 
141
  btn.click(dual_images, inputs=[img], outputs=[otpt])
142
  btn_scd.click(merge_descriptions_to_prompt, inputs=[minst, otp2, otp3], outputs=[otp4])
143
 
144
+ demo.launch(debug=True, share=True)
145
+ """
146
+ with gr.TabbedInterface(if_simple_description) as ifc:
147
+ ifc.launch(share=False, server_host="0.0.0.0", server_port=7860)
requirements.txt CHANGED
@@ -6,3 +6,4 @@ pillow==10.3.0
6
  together==1.1.5
7
  torch
8
  torchvision
 
 
6
  together==1.1.5
7
  torch
8
  torchvision
9
+ accelerate==0.30.1