mou3az commited on
Commit
c81a9ec
1 Parent(s): 67588de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -5
app.py CHANGED
@@ -202,6 +202,7 @@ messages2 = messages1.copy()
202
  messages3 = messages1.copy()
203
  messages4 = messages1.copy()
204
  messages5 = messages1.copy()
 
205
 
206
  def Chat_Message(history):
207
  global messages1
@@ -220,7 +221,7 @@ def Chat_Message(history):
220
  time.sleep(0.0025)
221
  yield history
222
 
223
- def Web_Search(history):
224
  global messages2
225
 
226
  message=history[-1][0]
@@ -408,6 +409,43 @@ def File_Interact(history,filepath):
408
  time.sleep(0.0025)
409
  yield history
410
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
411
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
412
  with gr.Row():
413
  gr.Markdown("""<span style='font-weight: bold; color: blue; font-size: large;'>Choose Your Mode</span>""")
@@ -431,13 +469,13 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
431
  submit.click(user, [msg, chatbot], [msg, chatbot], queue=True).then(Chat_Message, chatbot, chatbot)
432
  chatbot.like(print_like_dislike, None, None)
433
 
434
- with gr.Tab("Web-Search"):
435
  chatbot = gr.Chatbot(
436
  [],
437
  elem_id="chatbot",
438
  bubble_full_width=False,
439
  height=500,
440
- placeholder="<span style='font-weight: bold; color: blue; font-size: x-large;'>Demand What You Seek, And I'll Search The Web For The Most Relevant Information...</span>"
441
  )
442
  with gr.Row():
443
  msg = gr.Textbox(show_label=False, placeholder="Type a message...", scale=10, container=False)
@@ -445,8 +483,8 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
445
 
446
  clear = gr.ClearButton([msg, chatbot])
447
 
448
- msg.submit(user, [msg, chatbot], [msg, chatbot], queue=True).then(Web_Search, chatbot, chatbot)
449
- submit.click(user, [msg, chatbot], [msg, chatbot], queue=True).then(Web_Search, chatbot, chatbot)
450
  chatbot.like(print_like_dislike, None, None)
451
 
452
  with gr.Tab("Chart-Generator"):
@@ -513,5 +551,23 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
513
  submit.click(user3, [msg, chatbot, file_output], [msg, chatbot, file_output], queue=True).then(File_Interact, [chatbot, filepath],chatbot)
514
  chatbot.like(print_like_dislike, None, None)
515
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
516
  demo.queue(max_size=10, default_concurrency_limit=4)
517
  demo.launch(max_file_size="5mb", show_api=False, max_threads=50)
 
202
  messages3 = messages1.copy()
203
  messages4 = messages1.copy()
204
  messages5 = messages1.copy()
205
+ messages6 = messages1.copy()
206
 
207
  def Chat_Message(history):
208
  global messages1
 
221
  time.sleep(0.0025)
222
  yield history
223
 
224
+ def Internet_Search(history):
225
  global messages2
226
 
227
  message=history[-1][0]
 
409
  time.sleep(0.0025)
410
  yield history
411
 
412
+ def Explore_WebSite(history):
413
+ global messages6
414
+
415
+ message=history[-1][0]
416
+
417
+ links = [
418
+ 'https://huggingface.co/mou3az'
419
+ ]
420
+
421
+ result = "\n".join([read_data(link) for link in links])
422
+
423
+ content_data = normalize_text(result)
424
+
425
+ augmented_prompt = f"""
426
+ You are an AI designed to help understand and extract information from provided WebSite Content. Based on the user's Query, you may need to summarize the text, answer specific questions, or provide guidance.
427
+ Query: {message}
428
+ WebSite Content:
429
+ {source_knowledge}
430
+
431
+ #If the query is not related to specific WebSite Content, engage in general conversation or provide relevant information from other sources.
432
+ """
433
+
434
+ msg=HumanMessage(content=augmented_prompt)
435
+ messages6.append(msg)
436
+
437
+ if len(messages6) >= 2:
438
+ messages6 = messages6[-2:]
439
+
440
+ response = chat_model.invoke(messages6)
441
+ messages6.append(AIMessage(content=response.content))
442
+
443
+ history[-1][1] = ""
444
+ for character in response.content:
445
+ history[-1][1] += character
446
+ time.sleep(0.0025)
447
+ yield history
448
+
449
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
450
  with gr.Row():
451
  gr.Markdown("""<span style='font-weight: bold; color: blue; font-size: large;'>Choose Your Mode</span>""")
 
469
  submit.click(user, [msg, chatbot], [msg, chatbot], queue=True).then(Chat_Message, chatbot, chatbot)
470
  chatbot.like(print_like_dislike, None, None)
471
 
472
+ with gr.Tab("Internet-Search"):
473
  chatbot = gr.Chatbot(
474
  [],
475
  elem_id="chatbot",
476
  bubble_full_width=False,
477
  height=500,
478
+ placeholder="<span style='font-weight: bold; color: blue; font-size: x-large;'>Demand What You Seek, And I'll Search The Internet For The Most Relevant Information...</span>"
479
  )
480
  with gr.Row():
481
  msg = gr.Textbox(show_label=False, placeholder="Type a message...", scale=10, container=False)
 
483
 
484
  clear = gr.ClearButton([msg, chatbot])
485
 
486
+ msg.submit(user, [msg, chatbot], [msg, chatbot], queue=True).then(Internet_Search, chatbot, chatbot)
487
+ submit.click(user, [msg, chatbot], [msg, chatbot], queue=True).then(Internet_Search, chatbot, chatbot)
488
  chatbot.like(print_like_dislike, None, None)
489
 
490
  with gr.Tab("Chart-Generator"):
 
551
  submit.click(user3, [msg, chatbot, file_output], [msg, chatbot, file_output], queue=True).then(File_Interact, [chatbot, filepath],chatbot)
552
  chatbot.like(print_like_dislike, None, None)
553
 
554
+ with gr.Tab("Explore-WebSite"):
555
+ chatbot = gr.Chatbot(
556
+ [],
557
+ elem_id="chatbot",
558
+ bubble_full_width=False,
559
+ height=500,
560
+ placeholder="<span style='font-weight: bold; color: blue; font-size: x-large;'>Explore Any Information About Courses or Blogs In Our Web Site...</span>"
561
+ )
562
+ with gr.Row():
563
+ msg = gr.Textbox(show_label=False, placeholder="Type a message...", scale=10, container=False)
564
+ submit = gr.Button("➡️Send", scale=1)
565
+
566
+ clear = gr.ClearButton([msg, chatbot])
567
+
568
+ msg.submit(user, [msg, chatbot], [msg, chatbot], queue=True).then(Explore_WebSite, chatbot, chatbot)
569
+ submit.click(user, [msg, chatbot], [msg, chatbot], queue=True).then(Explore_WebSite, chatbot, chatbot)
570
+ chatbot.like(print_like_dislike, None, None)
571
+
572
  demo.queue(max_size=10, default_concurrency_limit=4)
573
  demo.launch(max_file_size="5mb", show_api=False, max_threads=50)