File size: 1,675 Bytes
577f602
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import requests
from streamlit import components
import os


# Accessing the secret
api_token = os.environ["api_key"]

# Endpoint Configuration
API_URL = "https://g68dcpgzzj69vo6p.us-east-1.aws.endpoints.huggingface.cloud"
headers = {
    "Accept": "application/json",
    "Authorization": f"Bearer {api_token}",
    "Content-Type": "application/json"
}

# Function to query the API with the prompt template
def query(user_input):
    system_prompt = 'You are a helpful assistant that provides accurate and concise responses.'
    formatted_input = f"<<SYS>>\n{system_prompt}\n<</SYS>>\n\n{user_input.strip()} [INST]\n\n"
    payload = {
        "inputs": formatted_input,
        "parameters": {}
    }
    response = requests.post(API_URL, headers=headers, json=payload)
    return response.json()

# Streamlit interface
st.title('Burmese GPT Beta')

# Example prompt (styled)
example_prompt = "Example: ပုဂံအကြောင်း ပြောပြနိုင်မလား?"
st.markdown(f'<p style="color:gray;">{example_prompt}</p>', unsafe_allow_html=True)

user_input = st.text_input("Ask a question in Burmese:")

if user_input:
    with st.spinner('Waiting for response...'):
        # Query the model
        output = query(user_input)

        # Display the result
        if isinstance(output, list):
            answer = output[0] if output else 'No response generated.'
            st.write(answer)
        elif 'error' in output:
            st.error(f"Error: {output['error']}")
        else:
            st.write('Unexpected response format.')

st.markdown("---")
st.markdown("Contact: { Dr.WaiYan, dr.waiyan@learnx.chat}")