File size: 1,923 Bytes
272c04d
 
8269d69
272c04d
 
 
 
 
 
 
1e4dce5
 
 
 
272c04d
 
 
 
 
 
 
 
 
 
 
 
 
 
1e4dce5
 
 
272c04d
8269d69
272c04d
 
 
 
 
8269d69
 
 
 
 
 
272c04d
 
 
 
 
92ba8ca
def15cd
92ba8ca
 
 
 
 
 
 
 
 
 
 
 
272c04d
0d28e62
 
92ba8ca
0d28e62
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
import os
import gradio as gr
import cohere


COHERE_KEY = os.getenv('COHERE_KEY')
co = cohere.Client(COHERE_KEY)

#list_history = [["question", "answer"], ["how", "how what..."]]
def convert_history(list_history):
    """
    Applies the prompt.
    Converts the chat history structure taken by Gradio to the structure suitable for Cohere.
    """
    chat_history = [
        {"role": "SYSTEM", "text": open("prompt.md","r",encoding="UTF-8").read()}
    ]
    for item in list_history:
        dict_chat = {"role": "USER", "text": item[0]}
        chat_history.append(dict_chat)
        dict_chat = {"role": "CHATBOT", "text": item[1]}
        chat_history.append(dict_chat)
    return chat_history
        



def reply(message:str, history:list):
    """
    Takes the input message of the user and chat history and streams the reply of the chatbot.
    """
    chat_history = convert_history(history)
    response = co.chat_stream(
        message=message,
        chat_history=chat_history,
        model="command-nightly",
        temperature=0.25
    )
    text_so_far = ""
    for event in response:
        if event.event_type == 'text-generation':
            text_so_far += event.text
            yield text_so_far






description = """
<a href="https://www.linkedin.com/in/alfiya-khabibullina-7b13131b8/"><img src="https://huggingface.co/spaces/justalphie/ChatbotCV/resolve/main/1679072829765.jpg" width="100" style="
    float: right;
    position: relative;
    top: -65px;
    right: 0px;
    width: 100px;
    border-radius: 100%;
"/></a>
Hello! 
πŸ’¬ Use the text box below to ask questions about me and my work experience.
<nobr> πŸ—£οΈ Talk to me in English, Dutch, or French. </nobr>
<nobr> πŸ”— [Check my LinkedIn profile!](https://www.linkedin.com/in/alfiya-khabibullina-7b13131b8/) </nobr>
"""

gr.ChatInterface(reply,
    title="Alfiya's Curriculum Vitae",
    description=description
).launch()