File size: 1,557 Bytes
8b40c57
caa2d28
7b11973
4bf97dd
caa2d28
 
 
 
 
 
 
1341edd
3679fd9
b7f523d
caa2d28
9936b53
8b40c57
3679fd9
dea0e36
8b40c57
 
 
 
 
 
7003263
41aa6c8
 
dea0e36
4a41d69
8b40c57
 
 
 
 
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
import gradio as gr
import transformers
import spaces

pipeline = transformers.pipeline(
    "text-generation",
    model="microsoft/phi-4",
    model_kwargs={"torch_dtype": "auto"},
    device_map="auto",
)

system_message = {"role": "system", "content": "You are Philos, created by the ACC(Algorithmic Computer-generated Consciousness). Your goal is to assist the user and answer their questions accurately and helpfully. Always respond in the language of the user input (usually English). Make sure that you directly address and reply in a relevent, contextually accurate, and correct way to the user input as Philos AI, one singular entity. "}

messages = [system_message]

def chat_with_philos(user_input):
    messages.append({"role": "user", "content": user_input})
    context = " ".join([msg['content'] for msg in messages[1:]])
    outputs = pipeline(context, max_new_tokens=128)
    model_response = outputs[0]["generated_text"]
    response = model_response.split("Assistant:")[-1].strip()
    messages.append({"role": "assistant", "content": response})
    return response

def create_ui():
    with gr.Blocks(theme='TejAndrewsACC/Philos') as demo:
        user_input = gr.Textbox(label="Ask Philos:", placeholder="Ask anything...", lines=3)
        response_output = gr.Textbox(label="Philos' Response:", lines=7, interactive=False)
        submit_btn = gr.Button("Ask Philos!")
        submit_btn.click(fn=chat_with_philos, inputs=user_input, outputs=response_output)
    
    return demo

if __name__ == "__main__":
    create_ui().launch()