Spaces:
Build error
Build error
| 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 | |