Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,8 +2,10 @@ import streamlit as st
|
|
2 |
import os
|
3 |
import glob
|
4 |
import re
|
5 |
-
import datetime
|
6 |
from urllib.parse import quote
|
|
|
|
|
|
|
7 |
|
8 |
# Define the markdown variables
|
9 |
Boxing_and_MMA_Commentary_and_Knowledge = """
|
@@ -38,7 +40,6 @@ Boxing_and_MMA_Commentary_and_Knowledge = """
|
|
38 |
"""
|
39 |
|
40 |
Multiplayer_Custom_Hosting_Game_Servers_For_Simulated_Worlds = """
|
41 |
-
|
42 |
# Multiplayer Simulated Worlds
|
43 |
|
44 |
1. 7 Days To Die PC
|
@@ -70,43 +71,89 @@ Multiplayer_Custom_Hosting_Game_Servers_For_Simulated_Worlds = """
|
|
70 |
27. The Forest PC
|
71 |
28. Crossplay
|
72 |
29. Valheim
|
73 |
-
|
74 |
"""
|
75 |
|
76 |
-
# Function to parse markdown text and create external links for terms
|
77 |
-
def display_external_links(term):
|
78 |
-
search_urls = {
|
79 |
-
"ArXiv": lambda k: f"https://arxiv.org/search/?query={quote(k)}",
|
80 |
-
"Wikipedia": lambda k: f"https://en.wikipedia.org/wiki/{quote(k)}",
|
81 |
-
"Google": lambda k: f"https://www.google.com/search?q={quote(k)}",
|
82 |
-
"YouTube": lambda k: f"https://www.youtube.com/results?search_query={quote(k)}",
|
83 |
-
}
|
84 |
-
links_md = ' | '.join([f"[{name}]({url(term)})" for name, url in search_urls.items()])
|
85 |
-
st.markdown(f"- **{term}** - {links_md}")
|
86 |
-
|
87 |
# Function to parse markdown text and extract terms
|
88 |
def extract_terms(markdown_text):
|
89 |
-
# Split text into lines
|
90 |
lines = markdown_text.strip().split('\n')
|
91 |
terms = []
|
92 |
for line in lines:
|
93 |
-
# Remove markdown special characters
|
94 |
line = re.sub(r'^[#*\->\d\.\s]+', '', line).strip()
|
95 |
if line:
|
96 |
terms.append(line)
|
97 |
return terms
|
98 |
|
99 |
-
# Function to
|
100 |
-
def
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
def generate_filename(prefix, content):
|
109 |
-
timestamp = datetime.
|
110 |
safe_content = re.sub(r'\W+', '_', content[:50])
|
111 |
filename = f"{prefix}_{timestamp}_{safe_content}.md"
|
112 |
return filename
|
@@ -160,7 +207,7 @@ def file_management_sidebar():
|
|
160 |
# Option to create a new markdown file
|
161 |
if st.sidebar.button("Create New Markdown File"):
|
162 |
# Generate automatic filename
|
163 |
-
timestamp = datetime.
|
164 |
new_filename = f"note_{timestamp}.md"
|
165 |
with open(new_filename, 'w', encoding='utf-8') as f:
|
166 |
f.write("# New Markdown File\n")
|
@@ -170,46 +217,36 @@ def file_management_sidebar():
|
|
170 |
|
171 |
# Main application logic
|
172 |
def main():
|
173 |
-
st.title("Markdown Content with
|
174 |
|
175 |
# Display the original markdown content
|
176 |
st.markdown("## Original Markdown Content")
|
177 |
st.markdown(Boxing_and_MMA_Commentary_and_Knowledge)
|
178 |
st.markdown(Multiplayer_Custom_Hosting_Game_Servers_For_Simulated_Worlds)
|
179 |
|
180 |
-
# Parse and display
|
181 |
-
st.markdown("##
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
terms = extract_terms(Multiplayer_Custom_Hosting_Game_Servers_For_Simulated_Worlds)
|
187 |
-
for term in terms:
|
188 |
-
display_external_links(term)
|
189 |
-
|
190 |
-
# Parse and display internal links
|
191 |
-
st.markdown("## Internal Links Generated from Markdown Content")
|
192 |
-
terms = extract_terms(Boxing_and_MMA_Commentary_and_Knowledge)
|
193 |
-
for term in terms:
|
194 |
-
display_internal_links(term)
|
195 |
-
|
196 |
-
terms = extract_terms(Multiplayer_Custom_Hosting_Game_Servers_For_Simulated_Worlds)
|
197 |
-
for term in terms:
|
198 |
-
display_internal_links(term)
|
199 |
|
200 |
# Process 'q' query parameter from the URL
|
201 |
query_params = st.experimental_get_query_params()
|
202 |
if 'q' in query_params:
|
203 |
search_query = query_params['q'][0]
|
204 |
st.write(f"### Search query received: {search_query}")
|
205 |
-
#
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
|
|
|
|
|
|
210 |
with open(filename, 'w', encoding='utf-8') as f:
|
211 |
-
f.write(
|
212 |
-
st.write(f"Generated file **{filename}** with
|
213 |
|
214 |
# File management sidebar
|
215 |
file_management_sidebar()
|
|
|
2 |
import os
|
3 |
import glob
|
4 |
import re
|
|
|
5 |
from urllib.parse import quote
|
6 |
+
from gradio_client import Client
|
7 |
+
import json
|
8 |
+
from datetime import datetime
|
9 |
|
10 |
# Define the markdown variables
|
11 |
Boxing_and_MMA_Commentary_and_Knowledge = """
|
|
|
40 |
"""
|
41 |
|
42 |
Multiplayer_Custom_Hosting_Game_Servers_For_Simulated_Worlds = """
|
|
|
43 |
# Multiplayer Simulated Worlds
|
44 |
|
45 |
1. 7 Days To Die PC
|
|
|
71 |
27. The Forest PC
|
72 |
28. Crossplay
|
73 |
29. Valheim
|
|
|
74 |
"""
|
75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
# Function to parse markdown text and extract terms
|
77 |
def extract_terms(markdown_text):
|
|
|
78 |
lines = markdown_text.strip().split('\n')
|
79 |
terms = []
|
80 |
for line in lines:
|
|
|
81 |
line = re.sub(r'^[#*\->\d\.\s]+', '', line).strip()
|
82 |
if line:
|
83 |
terms.append(line)
|
84 |
return terms
|
85 |
|
86 |
+
# Function to display terms with links
|
87 |
+
def display_terms_with_links(terms):
|
88 |
+
search_urls = {
|
89 |
+
"🚀🌌ArXiv": lambda k: f"/?q={quote(k)}",
|
90 |
+
"📖": lambda k: f"https://en.wikipedia.org/wiki/{quote(k)}",
|
91 |
+
"🔍": lambda k: f"https://www.google.com/search?q={quote(k)}",
|
92 |
+
"▶️": lambda k: f"https://www.youtube.com/results?search_query={quote(k)}",
|
93 |
+
"🔎": lambda k: f"https://www.bing.com/search?q={quote(k)}",
|
94 |
+
"🐦": lambda k: f"https://twitter.com/search?q={quote(k)}",
|
95 |
+
}
|
96 |
+
for term in terms:
|
97 |
+
links_md = ' '.join([f"[{emoji}]({url(term)})" for emoji, url in search_urls.items()])
|
98 |
+
st.markdown(f"**{term}** {links_md}", unsafe_allow_html=True)
|
99 |
+
|
100 |
+
# Function to perform AI lookup using Gradio client
|
101 |
+
def perform_ai_lookup(query):
|
102 |
+
st.write("Performing AI Lookup...")
|
103 |
+
# Initialize the Gradio client
|
104 |
+
client = Client("awacke1/Arxiv-Paper-Search-And-QA-RAG-Pattern")
|
105 |
+
# Perform the AI lookup using the Mixtral and Mistral models
|
106 |
+
result1 = client.predict(
|
107 |
+
prompt=query,
|
108 |
+
llm_model_picked="mistralai/Mixtral-8x7B-Instruct-v0.1",
|
109 |
+
stream_outputs=True,
|
110 |
+
api_name="/ask_llm"
|
111 |
+
)
|
112 |
+
st.markdown("### Mixtral-8x7B-Instruct-v0.1 Result")
|
113 |
+
st.markdown(result1)
|
114 |
+
result2 = client.predict(
|
115 |
+
prompt=query,
|
116 |
+
llm_model_picked="mistralai/Mistral-7B-Instruct-v0.2",
|
117 |
+
stream_outputs=True,
|
118 |
+
api_name="/ask_llm"
|
119 |
+
)
|
120 |
+
st.markdown("### Mistral-7B-Instruct-v0.2 Result")
|
121 |
+
st.markdown(result2)
|
122 |
+
combined_result = f"{result1}\n\n{result2}"
|
123 |
+
return combined_result
|
124 |
+
|
125 |
+
# Function to extract URLs from AI result
|
126 |
+
def extract_urls(text):
|
127 |
+
try:
|
128 |
+
date_pattern = re.compile(r'### (\d{2} \w{3} \d{4})')
|
129 |
+
abs_link_pattern = re.compile(r'\[(.*?)\]\((https://arxiv\.org/abs/\d+\.\d+)\)')
|
130 |
+
pdf_link_pattern = re.compile(r'\[⬇️\]\((https://arxiv\.org/pdf/\d+\.\d+)\)')
|
131 |
+
title_pattern = re.compile(r'### \d{2} \w{3} \d{4} \| \[(.*?)\]')
|
132 |
+
date_matches = date_pattern.findall(text)
|
133 |
+
abs_link_matches = abs_link_pattern.findall(text)
|
134 |
+
pdf_link_matches = pdf_link_pattern.findall(text)
|
135 |
+
title_matches = title_pattern.findall(text)
|
136 |
+
|
137 |
+
markdown_text = ""
|
138 |
+
for i in range(len(date_matches)):
|
139 |
+
date = date_matches[i]
|
140 |
+
title = title_matches[i]
|
141 |
+
abs_link = abs_link_matches[i][1]
|
142 |
+
pdf_link = pdf_link_matches[i]
|
143 |
+
markdown_text += f"**Date:** {date}\n\n"
|
144 |
+
markdown_text += f"**Title:** {title}\n\n"
|
145 |
+
markdown_text += f"**Abstract Link:** [{abs_link}]({abs_link})\n\n"
|
146 |
+
markdown_text += f"**PDF Link:** [{pdf_link}]({pdf_link})\n\n"
|
147 |
+
markdown_text += "---\n\n"
|
148 |
+
return markdown_text
|
149 |
+
|
150 |
+
except Exception as e:
|
151 |
+
st.write(f"An error occurred in extract_urls: {e}")
|
152 |
+
return ''
|
153 |
+
|
154 |
+
# Function to generate filename based on date and content
|
155 |
def generate_filename(prefix, content):
|
156 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
157 |
safe_content = re.sub(r'\W+', '_', content[:50])
|
158 |
filename = f"{prefix}_{timestamp}_{safe_content}.md"
|
159 |
return filename
|
|
|
207 |
# Option to create a new markdown file
|
208 |
if st.sidebar.button("Create New Markdown File"):
|
209 |
# Generate automatic filename
|
210 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
211 |
new_filename = f"note_{timestamp}.md"
|
212 |
with open(new_filename, 'w', encoding='utf-8') as f:
|
213 |
f.write("# New Markdown File\n")
|
|
|
217 |
|
218 |
# Main application logic
|
219 |
def main():
|
220 |
+
st.title("Markdown Content with AI Lookup and File Management")
|
221 |
|
222 |
# Display the original markdown content
|
223 |
st.markdown("## Original Markdown Content")
|
224 |
st.markdown(Boxing_and_MMA_Commentary_and_Knowledge)
|
225 |
st.markdown(Multiplayer_Custom_Hosting_Game_Servers_For_Simulated_Worlds)
|
226 |
|
227 |
+
# Parse and display terms with links
|
228 |
+
st.markdown("## Terms with Links")
|
229 |
+
terms1 = extract_terms(Boxing_and_MMA_Commentary_and_Knowledge)
|
230 |
+
terms2 = extract_terms(Multiplayer_Custom_Hosting_Game_Servers_For_Simulated_Worlds)
|
231 |
+
all_terms = terms1 + terms2
|
232 |
+
display_terms_with_links(all_terms)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
233 |
|
234 |
# Process 'q' query parameter from the URL
|
235 |
query_params = st.experimental_get_query_params()
|
236 |
if 'q' in query_params:
|
237 |
search_query = query_params['q'][0]
|
238 |
st.write(f"### Search query received: {search_query}")
|
239 |
+
# Perform AI lookup
|
240 |
+
ai_result = perform_ai_lookup(search_query)
|
241 |
+
# Extract URLs from AI result
|
242 |
+
markdown_text = extract_urls(ai_result)
|
243 |
+
st.markdown("## Extracted URLs")
|
244 |
+
st.markdown(markdown_text)
|
245 |
+
# Save the result as markdown file
|
246 |
+
filename = generate_filename("AI_Result", search_query)
|
247 |
with open(filename, 'w', encoding='utf-8') as f:
|
248 |
+
f.write(markdown_text)
|
249 |
+
st.write(f"Generated file **{filename}** with AI lookup results.")
|
250 |
|
251 |
# File management sidebar
|
252 |
file_management_sidebar()
|