File size: 2,606 Bytes
670064c
 
 
 
 
 
 
 
 
 
bc60149
 
 
 
 
 
 
 
 
670064c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12a19b9
670064c
 
 
 
 
 
 
 
 
 
 
 
1139efa
670064c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import streamlit as st
import random
import time
import git
import os
from google.api_core.exceptions import InternalServerError

flag = False
repo = st.text_input(label="Paste the .git link of repository.")
btn = st.button(label="Submit")

def clone_repo(repo):
    if os.path.exists("githubCode") and os.path.isdir("githubCode"):
        print("File already exists!!")
        pass
    else:
        print("Cloning repo!!")
        git.Repo.clone_from(repo,"githubCode")
        
if btn and not flag:
    clone_repo(repo=repo)
    # if os.path.exists("githubCode") and os.path.isdir("githubCode"):
    #     print("File already exists!!")
    #     pass
    # else:
    #     git.Repo.clone_from(repo,"githubCode")
    flag = True

# def response_generator():
#     response = random.choice(
#         [
#             "Hello there! How can I assist you today?",
#             "Hi, human! Is there anything I can help you with?",
#             "Do you need help?",
#         ]
#     )
#     for word in response.split():
#         yield word + " "
#         time.sleep(0.05)

st.title("Nile")

# Initialize chat history
if "messages" not in st.session_state:
    st.session_state.messages = []

# Display chat messages from history on app rerun
for message in st.session_state.messages:
    with st.chat_message(message["role"]):
        st.markdown(message["content"])

# Accept user input
if prompt := st.chat_input("What's your question ?"):
    from util import generate_assistant_response
    # Add user message to chat history
    st.session_state.messages.append({"role": "user", "content": prompt})
    # Display user message in chat message container
    with st.chat_message("user"):
        st.markdown(prompt)

    # Display assistant response in chat message container
    with st.chat_message("assistant"):

        try:
            response = generate_assistant_response(prompt)
        except InternalServerError as err:
            retry_attempts = 0
            MAX_RETRIES = 2
            if retry_attempts < MAX_RETRIES:
                retry_attempts += 1
                time.sleep(2)
                response = generate_assistant_response(prompt)
            else:
                # If retries are exhausted, log the error for further investigation
                response = "500 An internal error has occurred. Please retry or report in https://developers.generativeai.google/guide/troubleshooting"

        print(response)
        st.markdown(response)
    # Add assistant response to chat history
    st.session_state.messages.append({"role": "assistant", "content": response})