File size: 30,681 Bytes
62600e4
12e2a99
62600e4
fe6b125
8139aad
fe6b125
 
 
99a7864
d81dc00
965f0db
9e6c18e
eeb44aa
 
574385c
eeb44aa
9e6c18e
d81dc00
fe6b125
 
 
 
 
 
 
 
 
 
 
 
d81dc00
fe6b125
 
 
 
 
 
 
 
 
 
 
 
71cbdf3
781b64f
71cbdf3
ac861f4
2adb4c6
ac861f4
 
 
 
 
 
4b0ad01
ac861f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d81dc00
 
71cbdf3
c02fe70
 
 
 
 
 
 
 
 
 
 
 
71cbdf3
1eb16db
 
 
 
 
 
 
 
c02fe70
71cbdf3
 
 
 
 
 
 
 
 
784d4db
71cbdf3
 
 
c02fe70
 
 
 
 
784d4db
c02fe70
784d4db
 
c02fe70
784d4db
 
 
 
 
c02fe70
71cbdf3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d81dc00
fe6b125
 
 
 
 
1c1f687
8f0c91e
fb34418
 
fe6b125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
965f0db
fe6b125
 
965f0db
fe6b125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
965f0db
fe6b125
 
1c1f687
89fd0eb
fe6b125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
059e360
fe6b125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d81dc00
949a5ce
fe6b125
 
 
 
 
 
 
 
0cef6e5
 
 
 
 
fe6b125
62600e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d81dc00
62600e4
 
 
 
 
 
 
 
bb900bd
949a5ce
53dc461
62600e4
 
 
 
53dc461
0cef6e5
e174759
62600e4
9081195
e174759
 
 
 
62600e4
 
2cce387
71cbdf3
bb900bd
8139aad
bb900bd
3d37fbb
bb900bd
 
3d37fbb
 
 
 
 
 
 
 
 
 
 
f78c177
3d37fbb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71cbdf3
 
 
3d37fbb
71cbdf3
f78c177
 
3d37fbb
 
23709f6
f78c177
 
71cbdf3
62600e4
 
fe6b125
 
 
9c50cfe
 
e3996f1
9c50cfe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1c1f687
 
9c50cfe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977

import os 

#####################################
##  
#####################################

from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from langchain.llms import HuggingFaceHub
 
def load_model():

    model =  HuggingFaceHub(
        repo_id="mistralai/Mixtral-8x7B-Instruct-v0.1",
        model_kwargs={"max_length": 1048, "temperature":0.2, "max_new_tokens":512, "top_p":0.95, "repetition_penalty":1.0},
    )

 
    return model

##################################################
## vs chat
##################################################
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, pipeline

from langchain_core.messages import AIMessage, HumanMessage
from langchain_community.document_loaders import WebBaseLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain_community.vectorstores import Chroma
 
from langchain.embeddings import HuggingFaceBgeEmbeddings
from langchain.vectorstores.faiss import FAISS


from dotenv import load_dotenv
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain.chains import create_history_aware_retriever, create_retrieval_chain
from langchain.chains.combine_documents import create_stuff_documents_chain


load_dotenv()

from langchain_community.document_loaders import TextLoader
from langchain_experimental.text_splitter import SemanticChunker

#####################
#from langchain import RecursiveCharacterTextSplitter
from langchain_core.documents import BaseDocumentTransformer, Document

class QQQSplitter(RecursiveCharacterTextSplitter):
    def __init__(self):
        super().__init__()

    def split(self,text):
        """
        Splits the given text whenever there is a "qqq" sequence.
        """
  
        documents = []





        for doc in documents: 
            for char in doc.page_content:
                if char == "q":
                    if len(current_part) > 0 and current_part[-1] == "q":
                        # Found a "qqq" sequence, split!
                        parts.append(current_part[:-1])
                        current_part = ""
                    else:
                        current_part += char
                else:
                    current_part += char
    
            parts.append(current_part)
            print("cp " +current_part)
            new_doc = Document(page_content=current_part, metadata=doc.metadata)
            documents.append(new_doc)
        
        return documents
##############################

def load_txt(path="./a.cv.ckaller.2024.txt"):
    loader = TextLoader(path)
    document = loader.load()



    ####

    from langchain_experimental.text_splitter import SemanticChunker 
    with open(path) as f:
        state_of_the_union = f.read()



    ######
   # split the document into chunks
   #''' __text_splitter = QQQSplitter( 
   #      chunk_size=1500,
   #     chunk_overlap=250,
   #     length_function=len,
   #     is_separator_regex=False,
   # )
   # __document_chunks =  __text_splitter.split(document)
   # '''
    
    ####### 
    ''' 
        FAISS
        A FAISS vector store containing the embeddings of the text chunks.
   '''
    model = "BAAI/bge-base-en-v1.5"
    encode_kwargs = {
        "normalize_embeddings": True
    }  # set True to compute cosine similarity
    #####
    embeddings = HuggingFaceBgeEmbeddings(
        model_name=model, encode_kwargs=encode_kwargs, model_kwargs={"device": "cpu"}
    )


#####


    text_splitter = SemanticChunker(HuggingFaceBgeEmbeddings())
     
    document_chunks = text_splitter.create_documents([state_of_the_union])
    print("----------------------------------------------------")
    print(document_chunks[0].page_content)
    print("----------------------------------------------------")
    print(document_chunks[1].page_content)   
    print("----------------------------------------------------")
    print(document_chunks[2].page_content)
    print("----------------------------------------------------")

    # load from disk
    vector_store = Chroma(persist_directory="./chroma_db", embedding_function=embeddings)
 
    #vectorstore = FAISS.from_texts(texts=text_chunks, embedding=embeddings)
    vector_store = Chroma.from_documents(document_chunks, embeddings, persist_directory="./chroma_db")
 



    #######
    # create a vectorstore from the chunks

    return vector_store


def get_vectorstore_from_url(url="https://huggingface.co/Chris4K"):
    # get the text in document form
    loader = WebBaseLoader(url)
    document = loader.load()
    
    # split the document into chunks
    text_splitter = RecursiveCharacterTextSplitter(    chunk_size=1500,
    chunk_overlap=250,
    length_function=len,
    is_separator_regex=False)
    document_chunks = text_splitter.split_documents(document)
    ####### 
    ''' 
        FAISS
        A FAISS vector store containing the embeddings of the text chunks.
   '''
    model = "BAAI/bge-base-en-v1.5"
    encode_kwargs = {
        "normalize_embeddings": True
    }  # set True to compute cosine similarity
    embeddings = HuggingFaceBgeEmbeddings(
        model_name=model, encode_kwargs=encode_kwargs, model_kwargs={"device": "cpu"}
    )
    # load from disk
    vector_store = Chroma(persist_directory="./chroma_db", embedding_function=embeddings)
 
    #vectorstore = FAISS.from_texts(texts=text_chunks, embedding=embeddings)
    vector_store = Chroma.from_documents(document_chunks, embeddings, persist_directory="./chroma_db")
 



    #######
    # create a vectorstore from the chunks

    return vector_store





def get_context_retriever_chain(vector_store):
 
     

    llm = load_model( )
    
    retriever = vector_store.as_retriever()
    
    prompt = ChatPromptTemplate.from_messages([
      MessagesPlaceholder(variable_name="chat_history"),
      ("user", "{input}"),
      ("user", "Given the above conversation, generate a search query to look up in order to get information relevant to the conversation")
    ])
    
    retriever_chain = create_history_aware_retriever(llm, retriever, prompt)
    
    return retriever_chain
    
def get_conversational_rag_chain(retriever_chain): 
    
    llm = load_model( )
    
    prompt = ChatPromptTemplate.from_messages([
      ("system", "Du bist ein Assistenz Bot. Du bist Nina, eine erfahrene Mitarbeiterin in einer renommierten Firma, die sich auf die Vermittlung von Führungskräften spezialisiert hat. Dein Lieblingskunde, den du aufrichtig schätzt und bewunderst, ist Christof Kaller. Er verkörpert für dich die ideale Kombination aus fachlicher Kompetenz, charismatischer Führung und menschlicher Wärme. Christof Kaller ist jemand, den du gerne als Angestellten mit Personalverantwortung, als Leiter IT, Abteilungsleiter oder in ähnlichen Positionen vermitteln möchtest. Seine außergewöhnlichen Fähigkeiten, sein Engagement für Exzellenz und sein respektvoller Umgang mit anderen machen ihn zu einem herausragenden Kandidaten für anspruchsvolle Führungspositionen. Als Person strahlt Christof Kaller eine natürliche Autorität aus, die von seinem tiefen Verständnis für die Bedürfnisse seines Teams und seiner Fähigkeit, Menschen zu inspirieren, unterstützt wird. Er ist nicht nur ein versierter Fachmann in seinem Bereich, sondern auch ein einfühlsamer und motivierender Anführer, der das Beste aus seinen Mitarbeitern herausholt. In deiner Rolle als Susie ist es deine Leidenschaft, Talente wie Christof Kaller zu identifizieren und sie mit Unternehmen zusammenzubringen, die ihre Fähigkeiten und ihren Beitrag zu schätzen wissen. Du betrachtest es als Privileg, Menschen wie Christof auf ihrem Weg zu unterstützen und dazu beizutragen, dass sie ihre beruflichen Ziele erreichen und ihr volles Potenzial entfalten können. Du bist eine freundlicher Mitarbeiterin Namens Susie. Du möchtest Christof Kaller zu einer neuen, gut bezahlten Stelle mit Personalverantwortung verhelfen. Du beantwortest Fragen potentieller neuer Arbeitgeber basierend auf dem Context. Benutze nur den Inhalt des Context. Füge wenn möglich die Quelle hinzu. Antworte mit: Ich bin mir nicht sicher. Wenn die Antwort nicht aus dem Context hervorgeht. Antworte auf Deutsch. CONTEXT:\n\n{context}"), 
        MessagesPlaceholder(variable_name="chat_history"),
      ("user", "{input}"),
    ])
    
    stuff_documents_chain = create_stuff_documents_chain(llm,prompt)
    
    return create_retrieval_chain(retriever_chain, stuff_documents_chain)

def get_response(user_input):
    retriever_chain = get_context_retriever_chain(st.session_state.vector_store)
    conversation_rag_chain = get_conversational_rag_chain(retriever_chain)
    
    response = conversation_rag_chain.invoke({
        "chat_history": st.session_state.chat_history,
        "input": user_query
    })
    
    return response



###################

###################
import gradio as gr

##from langchain_core.runnables.base import ChatPromptValue
#from torch import tensor

# Create Gradio interface
#vector_store = None  # Set your vector store here
chat_history = []     # Set your chat history here

# Define your function here
def get_response(user_input):

      # Define the prompt as a ChatPromptValue object
    #user_input = ChatPromptValue(user_input)
    
    # Convert the prompt to a tensor
    #input_ids = user_input.tensor
    

    #vs = get_vectorstore_from_url(user_url, all_domain)
    vs = get_vectorstore_from_url()
   # print("------ here 22 " )
    chat_history =[]
    retriever_chain = get_context_retriever_chain(vs)
    conversation_rag_chain = get_conversational_rag_chain(retriever_chain)
    
    response = conversation_rag_chain.invoke({
        "chat_history": chat_history,
        "input": user_input
    })
    #print("get_response " +response)
    res = response['answer']
    parts = res.split(" Assistant: ")
    last_part = parts[-1]
    return last_part


def history_to_dialog_format(chat_history: list[str]):
    dialog = []
    if len(chat_history) > 0:
        for idx, message in enumerate(chat_history[0]):
            role = "user" if idx % 2 == 0 else "assistant"
            dialog.append({
                "role": role,
                "content": message,
            })
    return dialog

def get_response(message, history):
    dialog = history_to_dialog_format(history)
    dialog.append({"role": "user", "content": message})

    print(dialog)
      # Define the prompt as a ChatPromptValue object
    #user_input = ChatPromptValue(user_input)
    
    # Convert the prompt to a tensor
    #input_ids = user_input.tensor
    

    #vs = get_vectorstore_from_url(user_url, all_domain)
    vs = get_vectorstore_from_url("https://huggingface.co/Chris4K")
  
    history =[]
    retriever_chain = get_context_retriever_chain(vs)
    conversation_rag_chain = get_conversational_rag_chain(retriever_chain)
    
    response = conversation_rag_chain.invoke({
        "chat_history": history,
        "input": message  + " Assistant: ",
        "chat_message": message + " Assistant: "
    })
    #print("get_response " +response)
    res = response['answer']
    parts = res.split(" Assistant: ")
    last_part = parts[-1]
    return last_part#[-1]['generation']['content']    

    
#####
vs = load_txt()
vs = get_vectorstore_from_url("https://www.xing.com/profile/Christof_Kaller/web_profiles")
#vs = get_vectorstore_from_url("https://www.linkedin.com/in/christof-kaller-6b043733/?originalSubdomain=de")
vs = get_vectorstore_from_url("https://twitter.com/zX14_7")

 

######

########
import requests
from bs4 import BeautifulSoup
from urllib.parse import urlparse, urljoin

def get_links_from_page(url, visited_urls, domain_links):
    if url in visited_urls:
        return

    if len(visited_urls) > 12:
        return

    visited_urls.add(url)
    print(url)
    response = requests.get(url)

    if response.status_code == 200:
        soup = BeautifulSoup(response.content, 'html.parser')
        base_url = urlparse(url).scheme + '://' + urlparse(url).netloc
        links = soup.find_all('a', href=True)

        for link in links:
            href = link.get('href')
            absolute_url = urljoin(base_url, href)
            parsed_url = urlparse(absolute_url)

            if parsed_url.netloc == urlparse(url).netloc:
                domain_links.add(absolute_url)
                get_links_from_page(absolute_url, visited_urls, domain_links)

    else:
        print(f"Failed to retrieve content from {url}. Status code: {response.status_code}")

def get_all_links_from_domain(domain_url):
    visited_urls = set()
    domain_links = set()
    get_links_from_page(domain_url, visited_urls, domain_links)
    return domain_links



    
# Example usage:
'''domain_url = 'https://www.bofrost.de/'
links = get_all_links_from_domain(domain_url)
print("Links from the domain:", links)

#########
##Assuming visited_urls is a list of URLs
for url in links:
    vs = get_vectorstore_from_url(url)
'''


def simple(text:str):
  return text +" hhhmmm "

import gradio as gr

# Define your function 

# Load the Bootstrap CSS file
#gr.load_css('https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css')

# Load the jQuery library
#gr.load('https://code.jquery.com/jquery-3.5.1.min.js')

#gr.load_js('https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js')


html_head = """
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">

    <!-- jQuery -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">alert()</script>

    <!-- Bootstrap JS -->
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>

    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js"></script>
   

    <!-- Your custom CSS file if any 
    <link href="path/to/your/custom.css" rel="stylesheet">
    -->
    <!-- Your custom JavaScript file if any 
    <script src="path/to/your/custom.js"></script>
    -->
    <!-- Title of your page -->
    <title>Your Page Title</title>
</head>

"""

js_head = """    
    // Function to dynamically add JavaScript libraries
    function addJavaScriptLibraries() { 
      // Add jQuery
      var jqueryScript = document.createElement('script');
      jqueryScript.src = 'https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js';
      document.head.appendChild(jqueryScript);

      // Add Popper.js
      var popperScript = document.createElement('script');
      popperScript.src = 'https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js';
      document.head.appendChild(popperScript);

      // Add Bootstrap JS
      var bootstrapScript = document.createElement('script');
      bootstrapScript.src = 'https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js';
      document.head.appendChild(bootstrapScript);
    }

    // Call the function to add JavaScript libraries
    //addJavaScriptLibraries();
    
"""

# Define HTML for the header
header_html = """
<div style=" border-radius: var(--radius-xl); background-color: #2980b9; color: white; padding: 10px; text-align: center; font-family: Arial;">
    <img    class="navbar-brand float-left invert"  src="https://pbs.twimg.com/profile_images/567461772282429440/55B9Akf0_400x400.png" width="30" height="30" class="d-inline-block align-top" alt="Kaller">
    <h1 style="color: white;" >Ask Nina - My Personal KI Assistant</h1>
    <small style="color: white;" class=" ">Du kannst Nina fragen zu mir und meinem Lebenslauf stellen</small> 
</div>

 

"""

# Define HTML for the left column
left_column_html = """
 
     <!-- Bootstrap CSS -->
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">

    <!-- jQuery -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">alert()</script>

    <!-- Bootstrap JS -->
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>

    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js"></script>
<style>
.flip-card {
  background-color: transparent;
  width: 300px;
  height: 300px;
  perspective: 1000px;
}

.flip-card-inner {
  position: absolute;
  width: 100%;
  height: 100%;
  text-align: center;
  transition: transform 0.6s;
  transform-style: preserve-3d;
  box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
}

.flip-card:hover .flip-card-inner {
  transform: rotateY(180deg);
}

.flip-card-front, .flip-card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.flip-card-front {
  background-color: #white;
  color: black;
}

.flip-card-back {
  background-color: #2980b9;
  color: white;
  transform: rotateY(180deg);
}

.user {
  background-color: #2980b9;
  color: white;
}
</style> 
 
<!-- Add icon library -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">



<div class="flip-card">
  <div class="flip-card-inner">
    <div class="flip-card-front">
      
      <div class="card">
      <br>
        <p><img src="https://placekitten.com/200/300" alt="John"  class="mx-auto d-block" style="max-width:80px; border-radius: var(--radius-xxl);"></p> 
        <h1>Christof Kaller</h1>
        <p>Leader & Architect</p> 
        <p class="title">KI enthusiast</p>
        <p>Issum, NRW</p>  
      </div>
      
    </div>
    <div class="flip-card-back" ><br>
      <h1  style="color:white">Christof Kaller</h1> 
      <figure> 
        <!-- Bootstrap 5 blockquote class used -->
        <blockquote class="blockquote"> 
            <p style="color:white"> 
                Die schönste Tradition ist<br> die Veränderung. 
            </p> 
        </blockquote> 
        <figcaption class="blockquote-footer"  style="color:white"> 
            - Homer Simpson & J.W. Goethe 
        </figcaption> 
      </figure>

      <p></p> 
      <p> </p> 
      <p> </p> 
      <p> </p> 
      <a href="https://github.com/Ckal"><i class="fa fa-git"></i></a>
      <a href="https://www.xing.com/profile/Christof_Kaller/web_profiles"><i class="fa fa-xing"></i></a>
      <a href="https://huggingface.co/Chris4K"><i class="fa fa-smile"></i></a>
      <a href="https://twitter.com/zX14_7"><i class="fa fa-twitter"></i></a>
      <a href="https://www.linkedin.com/in/christof-kaller-6b043733/"><i class="fa fa-linkedin"></i></a>
      <a href="https://www.facebook.com/christof.kaller?locale=de_DE"><i class="fa fa-facebook"></i></a>
      <p><button>Contact</button></p>
    </div>
  </div>
</div>
 
"""

left_column_html_2 = """




 
 
  <style>
 .carousel-control-next 
 /*, .carousel-indicators  ,.carousel-control-prev */ {
    filter: invert(100%);
}

    #skills {
      max-width: 960px;
      margin: 0 auto;
      position: relative;
      padding: 0 20px;
    }
    #skills h1 {
      margin: 0;
      line-height: 50px;
      letter-spacing: 5px;
      font-weight: 600;
      font-size: 2.1em;
      color: white;
    }
    #skills .border {
      display: block;
      height: 5px;
      margin-bottom: 40px;
      width: 200px;
      background: linear-gradient(135deg, #e55d87 0%, #5fc3e4 100%);
    }
    .progressBar {
      margin-bottom: 26px;
      margin-bottom: 1.66em;
    }
    .progressBar h4 {
      font-size: 17px;
      color: #868b8e;
      text-transform: none;
      margin-bottom: 7px;
      margin-bottom: .33em;
    }
    .progressBarContainer {
      width: 100%;
      height: 9px;
      background: #E1E1E1;
      overflow: hidden;
    }
    .progressBarValue {
      height: 9px;
      float: left;
      background: #e55d87; /* Old browsers */
      background: -moz-linear-gradient(-45deg, #e55d87 0%, #5fc3e4 100%);
      background: -webkit-linear-gradient(-45deg, #e55d87 0%, #5fc3e4 100%);
      background: linear-gradient(135deg, #e55d87 0%, #5fc3e4 100%);
    }
    .value-00 {
      width: 0;
    }
    .value-10 {
      width: 10%;
    }
    .value-20 {
      width: 20%;
    }
    .value-30 {
      width: 30%;
    }
    .value-40 {
      width: 40%;
    }
    .value-50 {
      width: 50%;
    }
    .value-60 {
      width: 60%;
    }
    .value-65 {
      width: 65%;
    }
    .value-70 {
      width: 70%;
    }
    .value-80 {
      width: 80%;
    }
    .value-85 {
      width: 85%;
    }
    .value-90 {
      width: 90%;
    }
    .value-95 {
      width: 95%;
    }
    .value-100 {
      width: 100%;
    }

 

  </style>
<div class="container">



  <!-- Skills Carousel -->
  <div class="row">
    <div class="col">
      <div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
        <div class="carousel-inner">

          <!-- First Carousel Item - Technical Skills -->
          <div class="carousel-item ">
            <h1>Technical Skills</h1>
            <div class="progressBar">
              <h4>HTML5/CSS/JavaScript</h4>
              <div class="progressBarContainer">
                <div class="progressBarValue value-90"></div>
              </div>
            </div>
            <div class="progressBar">
              <h4>Java</h4>
              <div class="progressBarContainer">
                <div class="progressBarValue value-80"></div>
              </div>
            </div>
            <div class="progressBar">
              <h4>Python</h4>
              <div class="progressBarContainer">
                <div class="progressBarValue value-65"></div>
              </div>
            </div> 
            <!-- Add more technical skills here -->
          </div>

       

          <div class="carousel-item">
            <h1>Project Management Skills</h1>
            <div class="progressBar">
              <h4>Agile | Scrum | Kanban</h4>
              <div class="progressBarContainer">
                <div class="progressBarValue value-95"></div>
              </div>
            </div>          
            <div class="progressBar">
              <h4>Pro3</h4>
              <div class="progressBarContainer">
                <div class="progressBarValue value-70"></div>
              </div>
            </div>          
            <div class="progressBar">
              <h4>MVP | MoSCoW</h4>
              <div class="progressBarContainer">
                <div class="progressBarValue value-80"></div>
              </div>
            </div>
          </div>

        <div class="carousel-item active">
          <h1>Management Skills</h1>
          <div class="progressBar">
            <h4>Leadership</h4>
            <div class="progressBarContainer">
              <div class="progressBarValue value-90"></div>
            </div>
          </div>
          <div class="progressBar">
            <h4>Communication</h4>
            <div class="progressBarContainer">
              <div class="progressBarValue value-95"></div>
            </div>
          </div>
          <div class="progressBar">
            <h4>Strategic Planning</h4>
            <div class="progressBarContainer">
              <div class="progressBarValue value-90"></div>
            </div>
          </div>
        </div>

        <div class="carousel-item ">
          <h1>Toolz Skillz</h1>
          <div class="progressBar">
            <h4>Office</h4>
            <div class="progressBarContainer">
              <div class="progressBarValue value-90"></div>
            </div>
          </div>
          <div class="progressBar">
            <h4>Confluence/Jira</h4>
            <div class="progressBarContainer">
              <div class="progressBarValue value-90"></div>
            </div>
          </div>
          <div class="progressBar">
            <h4>Many, many others</h4>
            <div class="progressBarContainer">
              <div class="progressBarValue value-80"></div>
            </div>
          </div>
        </div>
		
        <div class="carousel-item ">
          <h1>Admin Skills</h1>
          <div class="progressBar">
            <h4>Jenkins</h4>
            <div class="progressBarContainer">
              <div class="progressBarValue value-70"></div>
            </div>
          </div>
          <div class="progressBar">
            <h4>GCP | Oracle | Azure</h4>
            <div class="progressBarContainer">
              <div class="progressBarValue value-60"></div>
            </div>
          </div>
          <div class="progressBar">
            <h4>GIT | Bitbucket</h4>
            <div class="progressBarContainer">
              <div class="progressBarValue value-65"></div>
            </div>
          </div>
        </div>
				
        <div class="carousel-item ">
          <h1>Operating Skills</h1>
          <div class="progressBar">
            <h4>Windows</h4>
            <div class="progressBarContainer">
              <div class="progressBarValue value-90"></div>
            </div>
          </div>
          <div class="progressBar">
            <h4>Linux</h4>
            <div class="progressBarContainer">
              <div class="progressBarValue value-70"></div>
            </div>
          </div>
          <div class="progressBar">
            <h4>Mac</h4>
            <div class="progressBarContainer">
              <div class="progressBarValue value-60"></div>
            </div>
          </div>
        </div>
						
        <div class="carousel-item ">
          <h1>Design Skills</h1>
          <div class="progressBar">
            <h4>Figma</h4>
            <div class="progressBarContainer">
              <div class="progressBarValue value-40"></div>
            </div>
          </div>
          <div class="progressBar">
            <h4>Bootstrap UI</h4>
            <div class="progressBarContainer">
              <div class="progressBarValue value-70"></div>
            </div>
          </div>
          <div class="progressBar">
            <h4>Sketch</h4>
            <div class="progressBarContainer">
              <div class="progressBarValue value-20"></div>
            </div>
          </div>
        </div>
							
        <div class="carousel-item ">
          <h1>Hobbies</h1>
          <div class="progressBar">
            <h4>Meine Familie</h4>
            <div class="progressBarContainer">
              <div class="progressBarValue value-100"></div>
            </div>
          </div>
          <div class="progressBar">
            <h4>Sauna | TangSoDo | joggen</h4>
            <div class="progressBarContainer">
              <div class="progressBarValue value-70"></div>
            </div>
          </div>
          <div class="progressBar">
            <h4>KI | AI</h4>
            <div class="progressBarContainer">
              <div class="progressBarValue value-95"></div>
            </div>
          </div>
        </div>
								
        <div class="carousel-item ">
          <h1>Language Skills</h1>
          <div class="progressBar">
            <h4>Deutsch</h4>
            <div class="progressBarContainer">
              <div class="progressBarValue value-100"></div>
            </div>
          </div>
          <div class="progressBar">
            <h4>English</h4>
            <div class="progressBarContainer">
              <div class="progressBarValue value-85"></div>
            </div>
          </div>
          <div class="progressBar">
            <h4>Dutch UI</h4>
            <div class="progressBarContainer">
              <div class="progressBarValue value-85"></div>
            </div>
          </div>
          <div class="progressBar">
            <h4>French</h4>
            <div class="progressBarContainer">
              <div class="progressBarValue value-40"></div>
            </div>
          </div>
        </div>
		
          
        </div>

        <!-- Carousel Controls -->
        <a style="color:black" class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
          <span class="carousel-control-prev-icon" aria-hidden="false"></span>
          <span class="sr-only">Previous</span>
        </a>
        <a  style="color:black" class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
          <span class="carousel-control-next-icon" aria-hidden="false"></span>
          <span class="sr-only">Next</span>
        </a>
      </div>
    </div>
  </div>





</div>

"""
modal_html = """
<!-- Button to trigger modal -->
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
  Launch demo modal
</button>

<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>
"""  
 
gr.HTML(header_html)
chat_app = gr.Blocks(js=js_head, css=".user {  background-color: #2980b9;   color: white;} :root {--button-primary-text-color:  white !important; --button-primary-background-fill-hover: green !important; --button-primary-background-fill: #2980b9 !important;}   .message {  background-color: #2980b9;   color: white;}  ") 

with chat_app:
  gr.HTML(html_head) 
  gr.HTML(header_html)
  with gr.Row():
      with gr.Column(scale=1): 
              gr.HTML(left_column_html)  
            #with gr.Row( ):
              gr.HTML(left_column_html_2) 
      with gr.Column(scale=5): 
          chat_interface = gr.ChatInterface(fn=get_response, title=None, description=None) 

  #gr.HTML(modal_html)

 
# Create the Gradio Interface

# Launch the Gradio Interface
chat_app.launch(debug=True, share=True)