PhilosBeta / app.py
TejAndrewsACC's picture
Update app.py
db7407a verified
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()