SOF_demo / app.py
halfrot's picture
Update app.py
b04318d
raw
history blame
1.83 kB
import streamlit as st
import datasets
from datasets import load_dataset
import pandas as pd
from streamlit.components.v1 import html
from streamlit import markdown
import re
import os
import time
import json
st.title('StackOverflow Question Demo')
library = st.radio('Select a library', ('numpy', 'tensorflow', 'pytorch', 'scipy', 'scikit-learn', 'pandas'))
question_path = './{}.txt'.format(library)
# question_path = 'numpy.txt'
# loading stackoverflow questions.
# using huggingface load_dataset function.
# not done yet
# @st.cache
# def load_data(path):
# return load_dataset('text', data_files = path, cache_dir = './data')
dataset = []
# dataset = load_data(question_path)
with open(question_path) as f:
lines = f.readlines()
question = ''
temp = {}
tag = ''
for line in lines:
if line == 'Origin:\n' or line == 'Function:\n' or re.match(r'A\d:\n', line):
if not tag:
tag = line[:-2]
else:
temp[tag] = question
question = ''
tag = line[:-2]
elif re.match(r'\d*\.\n', line):
if tag:
temp[tag] = question
dataset.append(temp)
question = ''
tag = ''
temp = {}
else:
if tag:
question += line + '\n'
temp[tag] = question
dataset.append(temp)
# Select index
number = st.number_input("Insert a index: range from",
min_value=0, max_value=len(dataset) - 1)
st.write('The current index is ', number)
data_index = int(number)
# Selece modification
options = tuple(dataset[data_index].keys())
modification = st.radio('Modification:',
options=options
)
st.write(dataset[data_index][modification])