File size: 1,715 Bytes
8af06a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import streamlit as st
import spacy
import wikipediaapi
import wikipedia
from wikipedia.exceptions import DisambiguationError
from transformers import TFAutoModel, AutoTokenizer
import numpy as np
import pandas as pd
import faiss
import datetime
import time
import random  # Import random library
from streamlit.components.v1 import html as html_component  # Import html component

# Add a list of random subjects
random_subjects = [
    "Computer Science",
    "Physics",
    "Chemistry",
    "Biology",
    "History",
    "Mathematics",
    "Geography",
    "Art",
    "Music",
    "Literature",
]

# ... (rest of the code)

def main():
    st.title("Streamlit Chat")

    name = st.text_input("Enter your name")
    message = st.text_input("Enter a topic to share from Wikipedia")

    # If no input is provided, select a random subject
    if not message:
        message = random.choice(random_subjects)

    if st.button("Submit"):
        
        # wiki
        df = get_wiki_summaryDF(message)
        
        save_message(name, message)
        save_message(name, df.to_string())  # Convert DataFrame to string before saving
        
        st.text("Message sent!")

    st.text("Chat history:")

    # Display chat history in a data grid
    with open("chat.txt", "a+") as f:
        f.seek(0)
        chat_history = f.read()

    # Wrap text in the chat history
    wrapped_chat_history = "<br>".join(chat_history.split("\n"))

    # Render chat history using the html component
    html_component(f"<pre style='white-space: pre-wrap;'>{wrapped_chat_history}</pre>")

    countdown = st.empty()
    t = 60
    while t:
        mins, secs = divmod(t, 60)
        countdown.text(f"Time remaining: {mins