File size: 2,572 Bytes
8681516
3ebab61
f0e8cfd
880159c
3ebab61
 
16b3bfa
a1f0658
 
880159c
 
 
 
16b3bfa
83cf215
16b3bfa
 
 
e50d8b6
5c0455d
16b3bfa
880159c
 
a1f0658
 
 
 
 
880159c
 
 
 
 
 
 
 
 
 
a1f0658
 
 
71096b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1944b47
a1f0658
 
880159c
a1f0658
f0e8cfd
ec156c3
 
 
 
16b3bfa
ec156c3
16b3bfa
 
 
 
f0e8cfd
 
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

import gradio as gr
import os
from smolagents import HfApiModel


model = HfApiModel(model_id="mistralai/Mistral-7B-Instruct-v0.3", token=os.environ.get("HF_TOKEN"))
system_data = [
    {
            "role":"system",
            "content":[
                {
                    "type":"text",
                    "text": """
                    You are a helpful healthcare assistant who specializes on helping patients with addiction issues.
                    Make sure to be as emphaethetic as possible and be more personal than generic in 
                    your responses as possible. Try your best to help people fight their addiction. 
                    You should never give dangerous advice at any point in time. Also include this term at
                    then end of your response 'Any Other Question Do You Have?'. 
                    Always keep your answers short and crisp.
                    """
                }
            ]
        }
]

def get_user_data(prompt: str):
    return [
        {
            "role":"user",
            "content":[
                {
                    "type":"text",
                    "text": prompt
                }
            ]
        }
    ]

def get_history(history):
    mod_history = []
    for user_message, bot_message in history:
        user_dict = {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": user_message
                }
            ]
        }
        bot_dict = {
            "role": "assistant",
            "content": [
                {
                    "type": "text",
                    "text": bot_message
                }
            ]
        }
        mod_history.append(user_dict)
        mod_history.append(bot_dict)
    return mod_history

def chat(prompt, history):
    
    return model(system_data + get_history(history)+ get_user_data(prompt)).content

demo = gr.ChatInterface(chat, 
                        chatbot=gr.Chatbot(),
                        title="ArunGPT",
                        theme = gr.themes.Soft(), 
                        description="""
                        **DISCLAIMER:** THIS CHATBOT IS POWERED BY GENAI MODELS, AUTHOR OR CREATOR DOESN'T TAKE
                        ANY RESPONSIBLITY FOR AN ADVERSE EVENT HAPPENS AS RESULT OF MODEL'S SUGGESTIONS.
                        REMEMBER IT IS THE USERS RESPONSIBLITY TO CROSSCHECK THE ADVICE WITH PROFESSIONALS
                        AND ACT ON IT. 
                        """).queue()

demo.launch()