|
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 |
|
from streamlit.components.v1 import html as html_component |
|
|
|
|
|
random_subjects = [ |
|
"Computer Science", |
|
"Physics", |
|
"Chemistry", |
|
"Biology", |
|
"History", |
|
"Mathematics", |
|
"Geography", |
|
"Art", |
|
"Music", |
|
"Literature", |
|
] |
|
|
|
|
|
|
|
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 not message: |
|
message = random.choice(random_subjects) |
|
|
|
if st.button("Submit"): |
|
|
|
|
|
df = get_wiki_summaryDF(message) |
|
|
|
save_message(name, message) |
|
save_message(name, df.to_string()) |
|
|
|
st.text("Message sent!") |
|
|
|
st.text("Chat history:") |
|
|
|
|
|
with open("chat.txt", "a+") as f: |
|
f.seek(0) |
|
chat_history = f.read() |
|
|
|
|
|
wrapped_chat_history = "<br>".join(chat_history.split("\n")) |
|
|
|
|
|
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 |
|
|