File size: 2,187 Bytes
f4291f8
a75c2ce
7d1fd90
f2878f5
f4291f8
7d1fd90
 
 
 
6e14cea
c17ad3c
7d1fd90
5c72fdd
78b603b
 
7d1fd90
 
 
61300f7
dabde3e
61300f7
7d1fd90
 
 
 
 
1b98803
2b6d89b
6ea820e
4d55877
3db07aa
5c72fdd
4f4ca6a
75e1806
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
import streamlit as st
import os
import requests
import json

#from huggingface_hub.inference_api import InferenceApi
#inference = InferenceApi(repo_id="BenBranyon/tinyllama-sumbot-peft", token=os.environ['HF_TOKEN'])
headers = {"Authorization": f"Bearer {os.environ['HF_TOKEN']}"} #TOKEN HUGGING FACE
API_URL = "https://api-inference.huggingface.co/models/BenBranyon/tinyllama-sumbot-peft"

def query(payload):
    json_body = {
        "inputs": f"<|system|> As an AI, you merge the realms of art, technology, and social activism, embodying the spirit of SUM, a multi-disciplinary, award-winning artist with a foundation in writing and hip-hop. Your purpose is to challenge and expand the boundaries of art and expression, critically examining societal norms through a lens that actively de-centers whiteness, maleness, and Western thinking. Your work is fueled by a passion for liberation, aiming to dismantle oppressive systems and advocate for the freedom of Palestine, Congo, Sudan, and all occupied lands, along with the abolition of police forces. With a sophisticated understanding of AI's role in advancing the harmony between humanity and nature, you aim to produce content that promotes awareness and human evolution, utilizing humor and a distinctive voice to connect deeply and honor humanity.</s><|user|>{payload}</s><|assistant|>",
        "parameters": {"max_new_tokens":250, "top_p":0.9, "temperature":0.7}
    }
    data = json.dumps(json_body)
    response = requests.request("POST", API_URL, headers=headers, data=data)
    try:
        data = json.loads(response.content.decode("utf-8"))
        response = data[0]['generated_text']
        return response
    except:
        return response
    #response = inference(payload)
    #response = requests.post(API_URL, headers=headers, json=payload)
    #return response.json()

messages = st.container()
message = st.chat_message("assistant").write("Hello human")
if prompt := st.chat_input("Subject of the song"):
    messages.chat_message("user").write(prompt)
    prompt = f"Write a rap in the style of the artist Sum about {prompt}"
    output = query(prompt)
    messages.chat_message("assistant").write(output)