Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import json
|
| 5 |
+
import altair as alt
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
import requests
|
| 8 |
+
from gpt4free import you
|
| 9 |
+
from streamlit_star_rating import st_star_rating
|
| 10 |
+
import requests
|
| 11 |
+
import time
|
| 12 |
+
from io import StringIO
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
st.text('')
|
| 16 |
+
st.title("Code Explainer")
|
| 17 |
+
st.text('')
|
| 18 |
+
|
| 19 |
+
source = st.radio("How would you like to start? Choose an option below",
|
| 20 |
+
("I want to input some text", "I want to upload a file"))
|
| 21 |
+
st.text('')
|
| 22 |
+
|
| 23 |
+
s_example = """
|
| 24 |
+
class Solution(object):
|
| 25 |
+
def isValid(self, s):
|
| 26 |
+
stack = []
|
| 27 |
+
mapping = {")": "(", "}": "{", "]": "["}
|
| 28 |
+
for char in s:
|
| 29 |
+
if char in mapping:
|
| 30 |
+
top_element = stack.pop() if stack else '#'
|
| 31 |
+
if mapping[char] != top_element:
|
| 32 |
+
return False
|
| 33 |
+
else:
|
| 34 |
+
stack.append(char)
|
| 35 |
+
return not stack
|
| 36 |
+
"""
|
| 37 |
+
|
| 38 |
+
if source == 'I want to input some text':
|
| 39 |
+
input_su = st.text_area("Use the example below or input your own code with appropriate indentations)", value=s_example, max_chars=10000, height=330)
|
| 40 |
+
if st.button('Explain Code'):
|
| 41 |
+
with st.spinner('Processing...'):
|
| 42 |
+
time.sleep(2)
|
| 43 |
+
st.markdown('___')
|
| 44 |
+
response = you.Completion.create(
|
| 45 |
+
prompt=f"Explain this code. Lets think Step by step. : {input_su}",
|
| 46 |
+
detailed=True,
|
| 47 |
+
include_links=True
|
| 48 |
+
)
|
| 49 |
+
st.write('Results!')
|
| 50 |
+
st.write(response.text)
|
| 51 |
+
stars = st_star_rating("How satisfied are you with the response?", 5, 0, 40)
|
| 52 |
+
st.balloons()
|
| 53 |
+
if source == 'I want to upload a file':
|
| 54 |
+
file = st.file_uploader('Upload your file here',type=['txt'])
|
| 55 |
+
if file is not None:
|
| 56 |
+
with st.spinner('Converting your code to explanations...'):
|
| 57 |
+
time.sleep(2)
|
| 58 |
+
stringio = StringIO(file.getvalue().decode("utf-8"))
|
| 59 |
+
string_data = stringio.read()
|
| 60 |
+
time.sleep(2)
|
| 61 |
+
st.markdown('___')
|
| 62 |
+
response = you.Completion.create(
|
| 63 |
+
prompt=f"Explain this code. Lets think Step by step : {string_data}",
|
| 64 |
+
detailed=True,
|
| 65 |
+
include_links=True
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
st.write(response.text)
|
| 69 |
+
stars = st_star_rating("How satisfied are you with the response?", 5, 0, 40)
|
| 70 |
+
st.caption("")
|
| 71 |
+
st.balloons()
|