ArchaveCommunity commited on
Commit
3dc65ea
Β·
verified Β·
1 Parent(s): 262015a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -22
app.py CHANGED
@@ -2,7 +2,6 @@ import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  from transformers import (
4
  AutoProcessor, LlavaForConditionalGeneration,
5
- IdeficsForConditionalGeneration,
6
  FuyuForCausalLM,
7
  )
8
  import torch
@@ -17,19 +16,13 @@ llava_model = LlavaForConditionalGeneration.from_pretrained(
17
  "llava-hf/llava-1.6-mistral-7b-hf", torch_dtype=torch.float16, device_map="auto"
18
  )
19
 
20
- # === 3. IDEFICS ===
21
- idefics_proc = AutoProcessor.from_pretrained("HuggingFaceM4/idefics-9b-instruct")
22
- idefics_model = IdeficsForConditionalGeneration.from_pretrained(
23
- "HuggingFaceM4/idefics-9b-instruct", torch_dtype=torch.float16, device_map="auto"
24
- )
25
-
26
- # === 4. Fuyu ===
27
  fuyu_proc = AutoProcessor.from_pretrained("adept/fuyu-8b")
28
  fuyu_model = FuyuForCausalLM.from_pretrained(
29
  "adept/fuyu-8b", torch_dtype=torch.float16, device_map="auto"
30
  )
31
 
32
- # === 5. Gabungan Multi-Model Handler ===
33
  def smart_respond(message, history, image=None):
34
  if image:
35
  results = []
@@ -43,16 +36,6 @@ def smart_respond(message, history, image=None):
43
  except Exception as e:
44
  results.append(f"LLaVA error: {e}")
45
 
46
- # β€” IDEFICS
47
- try:
48
- prompt = [{"role": "user", "content": [{"type": "image"}, {"type": "text", "text": message}]}]
49
- inputs = idefics_proc(prompt, images=[image], return_tensors="pt").to("cuda")
50
- output = idefics_model.generate(**inputs, max_new_tokens=512)
51
- idefics_reply = idefics_proc.decode(output[0], skip_special_tokens=True)
52
- results.append(f"πŸ“„ **IDEFICS**:\n{idefics_reply}")
53
- except Exception as e:
54
- results.append(f"IDEFICS error: {e}")
55
-
56
  # β€” Fuyu
57
  try:
58
  fuyu_inputs = fuyu_proc(images=image, text=message, return_tensors="pt").to("cuda")
@@ -78,9 +61,9 @@ def smart_respond(message, history, image=None):
78
  response += token
79
  yield response
80
 
81
- # === 6. Gradio Interface (ChatGPT-style) ===
82
  with gr.Blocks() as demo:
83
- gr.Markdown("## πŸ€– Elaina AI β€” Teks + Gambar (4 Model)")
84
  chatbot = gr.Chatbot()
85
  state = gr.State([])
86
 
@@ -104,6 +87,6 @@ with gr.Blocks() as demo:
104
  .then(bot_response, state, chatbot) \
105
  .then(lambda x: x, chatbot, state)
106
 
107
- # === 7. Jalankan ===
108
  if __name__ == "__main__":
109
  demo.launch()
 
2
  from huggingface_hub import InferenceClient
3
  from transformers import (
4
  AutoProcessor, LlavaForConditionalGeneration,
 
5
  FuyuForCausalLM,
6
  )
7
  import torch
 
16
  "llava-hf/llava-1.6-mistral-7b-hf", torch_dtype=torch.float16, device_map="auto"
17
  )
18
 
19
+ # === 3. Fuyu ===
 
 
 
 
 
 
20
  fuyu_proc = AutoProcessor.from_pretrained("adept/fuyu-8b")
21
  fuyu_model = FuyuForCausalLM.from_pretrained(
22
  "adept/fuyu-8b", torch_dtype=torch.float16, device_map="auto"
23
  )
24
 
25
+ # === 4. Gabungan Multi-Model Handler ===
26
  def smart_respond(message, history, image=None):
27
  if image:
28
  results = []
 
36
  except Exception as e:
37
  results.append(f"LLaVA error: {e}")
38
 
 
 
 
 
 
 
 
 
 
 
39
  # β€” Fuyu
40
  try:
41
  fuyu_inputs = fuyu_proc(images=image, text=message, return_tensors="pt").to("cuda")
 
61
  response += token
62
  yield response
63
 
64
+ # === 5. Gradio Interface (ChatGPT-style) ===
65
  with gr.Blocks() as demo:
66
+ gr.Markdown("## πŸ€– Elaina AI β€” Teks + Gambar (LLaVA + Fuyu + OpenChat)")
67
  chatbot = gr.Chatbot()
68
  state = gr.State([])
69
 
 
87
  .then(bot_response, state, chatbot) \
88
  .then(lambda x: x, chatbot, state)
89
 
90
+ # === 6. Jalankan ===
91
  if __name__ == "__main__":
92
  demo.launch()