Spaces:
Sleeping
Sleeping
Commit
·
1b8b75e
1
Parent(s):
832a78d
Add application file
Browse files- app.py +47 -0
- corpus.json +0 -0
- requirements.txt +7 -0
app.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import json
|
| 3 |
+
from hogragger import Hogragger
|
| 4 |
+
|
| 5 |
+
# Initialize the Hogragger class with your corpus path
|
| 6 |
+
hogragger = Hogragger(corpus_path='corpus.json') # Ensure corpus.json is in the correct path
|
| 7 |
+
|
| 8 |
+
# Streamlit app title
|
| 9 |
+
st.title("Hogragger Query Processor")
|
| 10 |
+
|
| 11 |
+
# Input text box for the query
|
| 12 |
+
query_input = st.text_area("Enter your query:", height=100)
|
| 13 |
+
|
| 14 |
+
# Button to process the query
|
| 15 |
+
if st.button("Process Query"):
|
| 16 |
+
if query_input:
|
| 17 |
+
st.write(f"Processing query: {query_input}")
|
| 18 |
+
|
| 19 |
+
# Step 3: Run the query through the pipeline
|
| 20 |
+
result = hogragger.process_query(query_input)
|
| 21 |
+
|
| 22 |
+
# Step 4: Format the result as JSON
|
| 23 |
+
result_dict = {
|
| 24 |
+
"query": query_input,
|
| 25 |
+
"answer": result['answer'],
|
| 26 |
+
"question_type": result['question_type'],
|
| 27 |
+
"evidence_list": [
|
| 28 |
+
{
|
| 29 |
+
"title": ev['title'],
|
| 30 |
+
"fact": ev['fact'],
|
| 31 |
+
"source": ev['source'],
|
| 32 |
+
"url": ev['url'],
|
| 33 |
+
"published_at": ev['published_at'],
|
| 34 |
+
"category": ev['category']
|
| 35 |
+
}
|
| 36 |
+
for ev in result['evidence_list'] # Optional: Limit if needed
|
| 37 |
+
]
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
# Convert the result to pretty JSON format
|
| 41 |
+
result_json = json.dumps(result_dict, indent=4)
|
| 42 |
+
|
| 43 |
+
# Display the JSON result on the web app
|
| 44 |
+
st.subheader("Result (JSON format):")
|
| 45 |
+
st.code(result_json, language='json')
|
| 46 |
+
else:
|
| 47 |
+
st.error("Please enter a query.")
|
corpus.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
sentence-transformers
|
| 3 |
+
transformers
|
| 4 |
+
torch
|
| 5 |
+
faiss-cpu
|
| 6 |
+
rank_bm25
|
| 7 |
+
huggingface_hub
|