Update app.py
Browse files
app.py
CHANGED
|
@@ -8,8 +8,9 @@ import spaces
|
|
| 8 |
import markdown
|
| 9 |
import requests
|
| 10 |
import torch
|
|
|
|
| 11 |
from PIL import Image
|
| 12 |
-
from transformers import MllamaForConditionalGeneration, AutoProcessor
|
| 13 |
|
| 14 |
|
| 15 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
|
@@ -27,6 +28,11 @@ model = MllamaForConditionalGeneration.from_pretrained(
|
|
| 27 |
processor = AutoProcessor.from_pretrained(model_id)
|
| 28 |
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
SYSTEM_INSTRUCTION="You are DailySnap, your job is to anlyse the given image and provide daily journal about the image and use some random time"
|
| 31 |
|
| 32 |
def extract_assistant_reply(input_string):
|
|
@@ -84,6 +90,28 @@ def generate__image_desc(image):
|
|
| 84 |
html_output = markdown.markdown(markdown_text)
|
| 85 |
return html_output
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
# Define activity categories based on detected objects
|
| 88 |
activity_categories = {
|
| 89 |
"Working": ["laptop", "computer", "keyboard", "office chair"],
|
|
|
|
| 8 |
import markdown
|
| 9 |
import requests
|
| 10 |
import torch
|
| 11 |
+
import io
|
| 12 |
from PIL import Image
|
| 13 |
+
from transformers import MllamaForConditionalGeneration, AutoProcessor,AutoModelForCausalLM, AutoTokenizer
|
| 14 |
|
| 15 |
|
| 16 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
|
|
|
| 28 |
processor = AutoProcessor.from_pretrained(model_id)
|
| 29 |
|
| 30 |
|
| 31 |
+
model_name = "Qwen/Qwen2.5-Coder-7B-Instruct"
|
| 32 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", device_map="auto")
|
| 33 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
SYSTEM_INSTRUCTION="You are DailySnap, your job is to anlyse the given image and provide daily journal about the image and use some random time"
|
| 37 |
|
| 38 |
def extract_assistant_reply(input_string):
|
|
|
|
| 90 |
html_output = markdown.markdown(markdown_text)
|
| 91 |
return html_output
|
| 92 |
|
| 93 |
+
@spaces.GPU
|
| 94 |
+
def generate_journal_infographics(code_input):
|
| 95 |
+
prompt = f"Generate daily journal inforgraphics using html for the following:\n\n{code_input}"
|
| 96 |
+
|
| 97 |
+
messages = [
|
| 98 |
+
{"role": "system", "content": "You are DailySnap, a highly efficient and intelligent assistant designed to generate infographics using htmnl bootstrap icon and generate highly appealing daily journal as per the user detail"},
|
| 99 |
+
{"role": "user", "content": prompt}
|
| 100 |
+
]
|
| 101 |
+
|
| 102 |
+
# Prepare inputs for the model
|
| 103 |
+
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 104 |
+
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 105 |
+
|
| 106 |
+
# Generate the documentation
|
| 107 |
+
generated_ids = model.generate(**model_inputs, max_new_tokens=4000)
|
| 108 |
+
generated_ids = [output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)]
|
| 109 |
+
documentation = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 110 |
+
print(documentation)
|
| 111 |
+
return documentation
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
|
| 115 |
# Define activity categories based on detected objects
|
| 116 |
activity_categories = {
|
| 117 |
"Working": ["laptop", "computer", "keyboard", "office chair"],
|