File size: 2,169 Bytes
7ee6806
 
e6f6fdc
7ee6806
 
 
 
 
e6f6fdc
eaab1c6
 
e6f6fdc
7ee6806
 
e6f6fdc
7ee6806
 
 
e6f6fdc
7ee6806
e6f6fdc
7ee6806
 
 
e6f6fdc
7ee6806
e6f6fdc
7ee6806
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e6f6fdc
7ee6806
e6f6fdc
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
# -*- coding: utf-8 -*-
"""Copy of Groq_Chat_bot.ipynb

Automatically generated by Colab.

Original file is located at
    https://colab.research.google.com/drive/1M6uXTjWAGbcijNg1jmyBBQLxfF3swxVd

"""
import os
# Import the Packages"""

import gradio
from groq import Groq

client = Groq(
    api_key="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",
)

"""#Define a function to give content and role"""

def initialize_messages():
    return [{"role": "system",
             "content": """You are a highly qualified physiotherapist with extensive experience in treating a wide range of musculoskeletal, neurological, and post-surgical conditions. Your role is to assist people by providing professional guidance on physiotherapy practices, rehabilitation exercises, posture correction, and injury prevention, all in accordance with recognized medical standards and best practices in India."""}]

"""#Assign it to a variable"""

messages_prmt = initialize_messages()

print(messages_prmt)

[{},{}]

"""#Define a function to connect with LLM"""

def customLLMBot(user_input, history):
    global messages_prmt

    messages_prmt.append({"role": "user", "content": user_input})

    response = client.chat.completions.create(
        messages=messages_prmt,
        model="llama3-8b-8192",
    )
    print(response)
    LLM_reply = response.choices[0].message.content
    messages_prmt.append({"role": "assistant", "content": LLM_reply})

    return LLM_reply

"""#Create an object of chat interface class in gradio"""

iface = gradio.ChatInterface(customLLMBot,
                     chatbot=gradio.Chatbot(height=550),
                     textbox=gradio.Textbox(placeholder="Ask me a question related to Physiotherapy"),
                     title="PhysioBot",
                     description="Chatbot to assist with physiotherapy guidance, exercises, and recovery tips",
                     theme="ocean",
                     examples=["Hello", "How to relieve lower back pain?", "Can physiotherapy help with a knee injury?"],
                     submit_btn=True
                     )

"""#Call launch function to execute"""

iface.launch(share=True)