martinakaduc
commited on
Commit
·
0337b97
1
Parent(s):
62bdcc8
Upload 4 files
Browse files- Logo BK.png +0 -0
- Logo CSE.png +0 -0
- README.md +9 -5
- app.py +72 -0
Logo BK.png
ADDED
Logo CSE.png
ADDED
README.md
CHANGED
@@ -1,9 +1,13 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
colorTo: blue
|
6 |
sdk: streamlit
|
7 |
-
sdk_version: 1.27.
|
|
|
8 |
pinned: false
|
9 |
-
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
title: Ura Introduciton
|
3 |
+
emoji: 📉
|
4 |
+
colorFrom: blue
|
5 |
colorTo: blue
|
6 |
sdk: streamlit
|
7 |
+
sdk_version: 1.27.2
|
8 |
+
app_file: app.py
|
9 |
pinned: false
|
10 |
+
license: mit
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
import json
|
4 |
+
import os
|
5 |
+
|
6 |
+
url = os.environ["SERVER_API"]
|
7 |
+
headers = {
|
8 |
+
'Content-Type': 'application/json'
|
9 |
+
}
|
10 |
+
|
11 |
+
if 'context' not in st.session_state:
|
12 |
+
st.session_state.context = ""
|
13 |
+
|
14 |
+
|
15 |
+
def answer_query(query):
|
16 |
+
payload = json.dumps({
|
17 |
+
"context": f"{st.session_state.context}",
|
18 |
+
"question": f"{query}",
|
19 |
+
"lang": "vi"
|
20 |
+
})
|
21 |
+
response = requests.request(
|
22 |
+
"POST",
|
23 |
+
url,
|
24 |
+
headers=headers,
|
25 |
+
data=payload,
|
26 |
+
timeout=300
|
27 |
+
)
|
28 |
+
answer = response.json()["answer"]
|
29 |
+
return answer
|
30 |
+
|
31 |
+
|
32 |
+
def main():
|
33 |
+
st.set_page_config(layout="wide")
|
34 |
+
st.image(["Logo BK.png", "Logo CSE.png"], width=120)
|
35 |
+
st.title("URA-LLaMa Playground")
|
36 |
+
|
37 |
+
st.subheader("Contexts")
|
38 |
+
use_manual_context = st.checkbox('Use manual context', value=True)
|
39 |
+
if use_manual_context:
|
40 |
+
context = st.text_area(
|
41 |
+
"Enter context",
|
42 |
+
value="Chương trình Khoa học máy tính của Khoa Khoa học và Kỹ thuật Máy tính (CSE), trường Đại học Bách Khoa (HCMUT) - Đại học Quốc gia thành phố Hồ Chí Minh được kiểm định bởi ABET.",
|
43 |
+
height=200,
|
44 |
+
max_chars=5000
|
45 |
+
)
|
46 |
+
if context != st.session_state.context:
|
47 |
+
st.session_state.context = ""
|
48 |
+
|
49 |
+
if context != "":
|
50 |
+
with st.spinner('Processing contexts...'):
|
51 |
+
st.session_state.context = context
|
52 |
+
else:
|
53 |
+
st.session_state.context = ""
|
54 |
+
|
55 |
+
st.subheader("Question")
|
56 |
+
question = st.text_input("Enter your question", placeholder="ABET là gì?")
|
57 |
+
button = st.button("Submit")
|
58 |
+
|
59 |
+
# Display the answer and additional context
|
60 |
+
st.subheader('Answer')
|
61 |
+
if button and question != "":
|
62 |
+
with st.spinner('Finding answers...'):
|
63 |
+
answer = answer_query(question)
|
64 |
+
else:
|
65 |
+
answer = ""
|
66 |
+
st.write(answer)
|
67 |
+
|
68 |
+
st.write("Powered by URA-LLaMa 7B")
|
69 |
+
|
70 |
+
|
71 |
+
if __name__ == "__main__":
|
72 |
+
main()
|