Spaces:
Running
on
Zero
Running
on
Zero
Update chatbot.py
Browse files- chatbot.py +4 -6
chatbot.py
CHANGED
@@ -25,7 +25,7 @@ import cv2
|
|
25 |
import re
|
26 |
import io # Add this import for working with image bytes
|
27 |
|
28 |
-
model_id = "llava-hf/llava-interleave-qwen-7b-hf"
|
29 |
processor = LlavaProcessor.from_pretrained(model_id)
|
30 |
model = LlavaForConditionalGeneration.from_pretrained(model_id, torch_dtype=torch.float16, use_flash_attention_2=True, low_cpu_mem_usage=True)
|
31 |
model.to("cuda")
|
@@ -67,7 +67,7 @@ EXAMPLES = [
|
|
67 |
],
|
68 |
[
|
69 |
{
|
70 |
-
"text": "
|
71 |
"files": [f"{examples_path}/example_images/elon_smoking.jpg",
|
72 |
f"{examples_path}/example_images/steve_jobs.jpg", ]
|
73 |
}
|
@@ -116,10 +116,8 @@ BOT_AVATAR = "OpenAI_logo.png"
|
|
116 |
def extract_text_from_webpage(html_content):
|
117 |
"""Extracts visible text from HTML content using BeautifulSoup."""
|
118 |
soup = BeautifulSoup(html_content, "html.parser")
|
119 |
-
# Remove unwanted tags
|
120 |
for tag in soup(["script", "style", "header", "footer", "nav", "form", "svg"]):
|
121 |
tag.extract()
|
122 |
-
# Get the remaining visible text
|
123 |
visible_text = soup.get_text(strip=True)
|
124 |
return visible_text
|
125 |
|
@@ -194,7 +192,7 @@ client_mixtral = InferenceClient("NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO")
|
|
194 |
client_mistral = InferenceClient("mistralai/Mistral-7B-Instruct-v0.3")
|
195 |
generate_kwargs = dict( max_new_tokens=4000, do_sample=True, stream=True, details=True, return_full_text=False )
|
196 |
|
197 |
-
system_llava = "<|im_start|>system\nYou are OpenGPT 4o, an exceptionally capable and versatile AI assistant meticulously crafted by KingNish. Your task is to fulfill users query in best possible way.
|
198 |
|
199 |
@spaces.GPU(duration=30, queue=False)
|
200 |
def model_inference(
|
@@ -278,7 +276,7 @@ def model_inference(
|
|
278 |
|
279 |
inputs = processor(prompt, image, return_tensors="pt").to("cuda", torch.float16)
|
280 |
streamer = TextIteratorStreamer(processor, **{"skip_special_tokens": True})
|
281 |
-
generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=
|
282 |
generated_text = ""
|
283 |
|
284 |
thread = Thread(target=model.generate, kwargs=generation_kwargs)
|
|
|
25 |
import re
|
26 |
import io # Add this import for working with image bytes
|
27 |
|
28 |
+
model_id = "llava-hf/llava-interleave-qwen-7b-dpo-hf"
|
29 |
processor = LlavaProcessor.from_pretrained(model_id)
|
30 |
model = LlavaForConditionalGeneration.from_pretrained(model_id, torch_dtype=torch.float16, use_flash_attention_2=True, low_cpu_mem_usage=True)
|
31 |
model.to("cuda")
|
|
|
67 |
],
|
68 |
[
|
69 |
{
|
70 |
+
"text": "Who are they? Tell me about both of them",
|
71 |
"files": [f"{examples_path}/example_images/elon_smoking.jpg",
|
72 |
f"{examples_path}/example_images/steve_jobs.jpg", ]
|
73 |
}
|
|
|
116 |
def extract_text_from_webpage(html_content):
|
117 |
"""Extracts visible text from HTML content using BeautifulSoup."""
|
118 |
soup = BeautifulSoup(html_content, "html.parser")
|
|
|
119 |
for tag in soup(["script", "style", "header", "footer", "nav", "form", "svg"]):
|
120 |
tag.extract()
|
|
|
121 |
visible_text = soup.get_text(strip=True)
|
122 |
return visible_text
|
123 |
|
|
|
192 |
client_mistral = InferenceClient("mistralai/Mistral-7B-Instruct-v0.3")
|
193 |
generate_kwargs = dict( max_new_tokens=4000, do_sample=True, stream=True, details=True, return_full_text=False )
|
194 |
|
195 |
+
system_llava = "<|im_start|>system\nYou are OpenGPT 4o, an exceptionally capable and versatile AI assistant meticulously crafted by KingNish. Your task is to fulfill users query in best possible way. You are provided with image, videos and 3d structures as input with question your task is to give best possible result and explaination to user.<|im_end|>"
|
196 |
|
197 |
@spaces.GPU(duration=30, queue=False)
|
198 |
def model_inference(
|
|
|
276 |
|
277 |
inputs = processor(prompt, image, return_tensors="pt").to("cuda", torch.float16)
|
278 |
streamer = TextIteratorStreamer(processor, **{"skip_special_tokens": True})
|
279 |
+
generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=2048)
|
280 |
generated_text = ""
|
281 |
|
282 |
thread = Thread(target=model.generate, kwargs=generation_kwargs)
|