awacke1 commited on
Commit
8af06a5
1 Parent(s): f8500eb

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -0
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import spacy
3
+ import wikipediaapi
4
+ import wikipedia
5
+ from wikipedia.exceptions import DisambiguationError
6
+ from transformers import TFAutoModel, AutoTokenizer
7
+ import numpy as np
8
+ import pandas as pd
9
+ import faiss
10
+ import datetime
11
+ import time
12
+ import random # Import random library
13
+ from streamlit.components.v1 import html as html_component # Import html component
14
+
15
+ # Add a list of random subjects
16
+ random_subjects = [
17
+ "Computer Science",
18
+ "Physics",
19
+ "Chemistry",
20
+ "Biology",
21
+ "History",
22
+ "Mathematics",
23
+ "Geography",
24
+ "Art",
25
+ "Music",
26
+ "Literature",
27
+ ]
28
+
29
+ # ... (rest of the code)
30
+
31
+ def main():
32
+ st.title("Streamlit Chat")
33
+
34
+ name = st.text_input("Enter your name")
35
+ message = st.text_input("Enter a topic to share from Wikipedia")
36
+
37
+ # If no input is provided, select a random subject
38
+ if not message:
39
+ message = random.choice(random_subjects)
40
+
41
+ if st.button("Submit"):
42
+
43
+ # wiki
44
+ df = get_wiki_summaryDF(message)
45
+
46
+ save_message(name, message)
47
+ save_message(name, df.to_string()) # Convert DataFrame to string before saving
48
+
49
+ st.text("Message sent!")
50
+
51
+ st.text("Chat history:")
52
+
53
+ # Display chat history in a data grid
54
+ with open("chat.txt", "a+") as f:
55
+ f.seek(0)
56
+ chat_history = f.read()
57
+
58
+ # Wrap text in the chat history
59
+ wrapped_chat_history = "<br>".join(chat_history.split("\n"))
60
+
61
+ # Render chat history using the html component
62
+ html_component(f"<pre style='white-space: pre-wrap;'>{wrapped_chat_history}</pre>")
63
+
64
+ countdown = st.empty()
65
+ t = 60
66
+ while t:
67
+ mins, secs = divmod(t, 60)
68
+ countdown.text(f"Time remaining: {mins