Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +53 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
from streamlit import components
|
4 |
+
import os
|
5 |
+
|
6 |
+
|
7 |
+
# Accessing the secret
|
8 |
+
api_token = os.environ["api_key"]
|
9 |
+
|
10 |
+
# Endpoint Configuration
|
11 |
+
API_URL = "https://g68dcpgzzj69vo6p.us-east-1.aws.endpoints.huggingface.cloud"
|
12 |
+
headers = {
|
13 |
+
"Accept": "application/json",
|
14 |
+
"Authorization": f"Bearer {api_token}",
|
15 |
+
"Content-Type": "application/json"
|
16 |
+
}
|
17 |
+
|
18 |
+
# Function to query the API with the prompt template
|
19 |
+
def query(user_input):
|
20 |
+
system_prompt = 'You are a helpful assistant that provides accurate and concise responses.'
|
21 |
+
formatted_input = f"<<SYS>>\n{system_prompt}\n<</SYS>>\n\n{user_input.strip()} [INST]\n\n"
|
22 |
+
payload = {
|
23 |
+
"inputs": formatted_input,
|
24 |
+
"parameters": {}
|
25 |
+
}
|
26 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
27 |
+
return response.json()
|
28 |
+
|
29 |
+
# Streamlit interface
|
30 |
+
st.title('Burmese GPT Beta')
|
31 |
+
|
32 |
+
# Example prompt (styled)
|
33 |
+
example_prompt = "Example: ပုဂံအကြောင်း ပြောပြနိုင်မလား?"
|
34 |
+
st.markdown(f'<p style="color:gray;">{example_prompt}</p>', unsafe_allow_html=True)
|
35 |
+
|
36 |
+
user_input = st.text_input("Ask a question in Burmese:")
|
37 |
+
|
38 |
+
if user_input:
|
39 |
+
with st.spinner('Waiting for response...'):
|
40 |
+
# Query the model
|
41 |
+
output = query(user_input)
|
42 |
+
|
43 |
+
# Display the result
|
44 |
+
if isinstance(output, list):
|
45 |
+
answer = output[0] if output else 'No response generated.'
|
46 |
+
st.write(answer)
|
47 |
+
elif 'error' in output:
|
48 |
+
st.error(f"Error: {output['error']}")
|
49 |
+
else:
|
50 |
+
st.write('Unexpected response format.')
|
51 |
+
|
52 |
+
st.markdown("---")
|
53 |
+
st.markdown("Contact: { Dr.WaiYan, [email protected]}")
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
requests
|