File size: 1,352 Bytes
faad248
ee4f217
faad248
8b522b2
 
b11ec81
 
 
 
 
 
 
 
 
c46e011
b11ec81
 
f2baf1b
c46e011
f2baf1b
b11ec81
83f7f16
 
 
 
04449e2
 
83f7f16
ebc0d7d
 
c46e011
ebc0d7d
 
d2c0858
ebc0d7d
4474c1d
 
 
c46e011
4474c1d
ebc0d7d
 
 
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
import streamlit as st
import requests

#API_URL = "https://g8u06j6fqi4vyi5i.eu-west-1.aws.endpoints.huggingface.cloud"
API_URL = "https://gavdzeg3p9lv0fx0.us-east-1.aws.endpoints.huggingface.cloud"
headers = {
	"Accept" : "application/json",
	"Content-Type": "application/json" 
}

def query(payload):
	response = requests.post(API_URL, headers=headers, json=payload)
	return response.json()

def get_completion(prompt, temperature=0.6):
    output = query({
	"inputs": f"{prompt}",
	"parameters": {
        "temperature":temperature,
    }
    })
    #If expected format, output text as usual
    if output and isinstance(output, list) and "generated_text" in output[0]:
        return output[0]["generated_text"]
    # Debugging
    if "error" in output:
        return output["error"]
    return str(output.keys())

def main():
    st.title('UiA ai koordinator\n Llama 3 8b text completion')

    user_input = st.text_area("Enter your prompt:", height=300)
    temperature = st.slider('Select the temperature:', 0.0001, 2.0, 0.6)
    
    with st.spinner('Generating completion...'):
        if st.button('Generate'):
            # Get the model's completion
            completion = get_completion(user_input, temperature)
            st.text_area("Model Completion:", value=completion, height=300, key="2")

if __name__ == '__main__':
    main()