File size: 1,557 Bytes
1b8b75e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import json
from hogragger import Hogragger

# Initialize the Hogragger class with your corpus path
hogragger = Hogragger(corpus_path='corpus.json')  # Ensure corpus.json is in the correct path

# Streamlit app title
st.title("Hogragger Query Processor")

# Input text box for the query
query_input = st.text_area("Enter your query:", height=100)

# Button to process the query
if st.button("Process Query"):
    if query_input:
        st.write(f"Processing query: {query_input}")
        
        # Step 3: Run the query through the pipeline
        result = hogragger.process_query(query_input)

        # Step 4: Format the result as JSON
        result_dict = {
            "query": query_input,
            "answer": result['answer'],
            "question_type": result['question_type'],
            "evidence_list": [
                {
                    "title": ev['title'],
                    "fact": ev['fact'],
                    "source": ev['source'],
                    "url": ev['url'],
                    "published_at": ev['published_at'],
                    "category": ev['category']
                }
                for ev in result['evidence_list']  # Optional: Limit if needed
            ]
        }

        # Convert the result to pretty JSON format
        result_json = json.dumps(result_dict, indent=4)

        # Display the JSON result on the web app
        st.subheader("Result (JSON format):")
        st.code(result_json, language='json')
    else:
        st.error("Please enter a query.")