KingNish commited on
Commit
06bea5a
1 Parent(s): e0362cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -17
app.py CHANGED
@@ -36,17 +36,7 @@ def llava(message, history):
36
  prompt = f"<|im_start|>user <image>\n{user_prompt}<|im_end|><|im_start|>assistant"
37
 
38
  inputs = processor(prompt, image, return_tensors="pt")
39
- streamer = TextIteratorStreamer(processor, skip_prompt=True, **{"skip_special_tokens": True})
40
- generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=1024)
41
- generated_text = ""
42
-
43
- thread = Thread(target=model.generate, kwargs=generation_kwargs)
44
- thread.start()
45
-
46
- buffer = ""
47
- for new_text in streamer:
48
- buffer += new_text
49
- yield buffer
50
 
51
  def extract_text_from_webpage(html_content):
52
  soup = BeautifulSoup(html_content, 'html.parser')
@@ -97,8 +87,17 @@ def respond(message, history):
97
  user_prompt = message
98
  # Handle image processing
99
  if message["files"]:
100
- streamer = llava(message, history)
101
- yield streamer
 
 
 
 
 
 
 
 
 
102
  else:
103
  functions_metadata = [
104
  {"type": "function", "function": {"name": "web_search", "description": "Search query on google", "parameters": {"type": "object", "properties": {"query": {"type": "string", "description": "web search query"}}, "required": ["query"]}}},
@@ -144,16 +143,25 @@ def respond(message, history):
144
  yield output
145
  elif json_data["name"] == "image_generation":
146
  query = json_data["arguments"]["query"]
147
- gr.Info("Generating Image, Please wait...")
148
  seed = random.randint(1, 99999)
149
  query = query.replace(" ", "%20")
150
  image = f"![](https://image.pollinations.ai/prompt/{query}?seed={seed})"
151
  yield image
152
- time.sleep(5)
153
  gr.Info("We are going to Update Our Image Generation Engine to more powerful ones in Next Update. ThankYou")
154
  elif json_data["name"] == "image_qna":
155
- messages = f"<|start_header_id|>system\nYou are OpenGPT 4o mini a helpful assistant made by KingNish. You are provide with both images and captions and Your task is to answer of user with help of caption provided. Answer in human style and show emotions.<|end_header_id|>"
156
- yield llava(message, history)
 
 
 
 
 
 
 
 
 
157
  else:
158
  messages = f"<|start_header_id|>system\nYou are OpenGPT 4o mini a helpful assistant made by KingNish. You answers users query like human friend. You are also Expert in every field and also learn and try to answer from contexts related to previous question. Try your best to give best response possible to user. You also try to show emotions using Emojis and reply like human, use short forms, friendly tone and emotions.<|end_header_id|>"
159
  for msg in history:
 
36
  prompt = f"<|im_start|>user <image>\n{user_prompt}<|im_end|><|im_start|>assistant"
37
 
38
  inputs = processor(prompt, image, return_tensors="pt")
39
+ return inputs
 
 
 
 
 
 
 
 
 
 
40
 
41
  def extract_text_from_webpage(html_content):
42
  soup = BeautifulSoup(html_content, 'html.parser')
 
87
  user_prompt = message
88
  # Handle image processing
89
  if message["files"]:
90
+ inputs = llava(message, history)
91
+ streamer = TextIteratorStreamer(processor, skip_prompt=True, **{"skip_special_tokens": True})
92
+ generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=1024)
93
+
94
+ thread = Thread(target=model.generate, kwargs=generation_kwargs)
95
+ thread.start()
96
+
97
+ buffer = ""
98
+ for new_text in streamer:
99
+ buffer += new_text
100
+ yield buffer
101
  else:
102
  functions_metadata = [
103
  {"type": "function", "function": {"name": "web_search", "description": "Search query on google", "parameters": {"type": "object", "properties": {"query": {"type": "string", "description": "web search query"}}, "required": ["query"]}}},
 
143
  yield output
144
  elif json_data["name"] == "image_generation":
145
  query = json_data["arguments"]["query"]
146
+ gr.Info("Generating Image, Please wait 10 sec...")
147
  seed = random.randint(1, 99999)
148
  query = query.replace(" ", "%20")
149
  image = f"![](https://image.pollinations.ai/prompt/{query}?seed={seed})"
150
  yield image
151
+ time.sleep(8)
152
  gr.Info("We are going to Update Our Image Generation Engine to more powerful ones in Next Update. ThankYou")
153
  elif json_data["name"] == "image_qna":
154
+ inputs = llava(message, history)
155
+ streamer = TextIteratorStreamer(processor, skip_prompt=True, **{"skip_special_tokens": True})
156
+ generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=1024)
157
+
158
+ thread = Thread(target=model.generate, kwargs=generation_kwargs)
159
+ thread.start()
160
+
161
+ buffer = ""
162
+ for new_text in streamer:
163
+ buffer += new_text
164
+ yield buffer
165
  else:
166
  messages = f"<|start_header_id|>system\nYou are OpenGPT 4o mini a helpful assistant made by KingNish. You answers users query like human friend. You are also Expert in every field and also learn and try to answer from contexts related to previous question. Try your best to give best response possible to user. You also try to show emotions using Emojis and reply like human, use short forms, friendly tone and emotions.<|end_header_id|>"
167
  for msg in history: