Spaces:
Runtime error
Runtime error
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, [email protected]}") |