Updated description
Browse files
app.py
CHANGED
@@ -48,7 +48,6 @@ def get_github_docs(repo_link):
|
|
48 |
|
49 |
#Code for creating a new space for the user
|
50 |
def create_space(repo_link, hf_token):
|
51 |
-
print("***********INSIDE CREATE SPACE***************")
|
52 |
repo_name = repo_link.split('/')[-1]
|
53 |
api = HfApi(token=hf_token)
|
54 |
repo_url = api.create_repo(
|
@@ -61,9 +60,7 @@ def create_space(repo_link, hf_token):
|
|
61 |
#Code for creating the search index
|
62 |
#Saving search index to disk
|
63 |
def create_search_index(repo_link, openai_api_key):
|
64 |
-
|
65 |
-
#openai = OpenAI(temperature=0, openai_api_key=openai_api_key )
|
66 |
-
sources = get_github_docs(repo_link) #"gradio-app", "gradio"
|
67 |
source_chunks = []
|
68 |
splitter = CharacterTextSplitter(separator=" ", chunk_size=1024, chunk_overlap=0)
|
69 |
for source in sources:
|
@@ -78,7 +75,6 @@ def create_search_index(repo_link, openai_api_key):
|
|
78 |
return "search_index.pickle"
|
79 |
|
80 |
def upload_files_to_space(repo_link, hf_token):
|
81 |
-
print("***********INSIDE UPLOAD FILES TO SPACE***************")
|
82 |
repo_name = repo_link.split('/')[-1]
|
83 |
api = HfApi(token=hf_token)
|
84 |
user_name = whoami(token=hf_token)['name']
|
@@ -87,7 +83,6 @@ def upload_files_to_space(repo_link, hf_token):
|
|
87 |
with open("template/app_og.py", "r") as f:
|
88 |
app = f.read()
|
89 |
app = app.replace("$RepoName", repo_name)
|
90 |
-
#app = app.replace("$space_id", whoami(token=token)["name"] + "/" + model_id.split("/")[-1])
|
91 |
|
92 |
#Saving the new app.py file to disk
|
93 |
with open("template/app.py", "w") as f:
|
@@ -120,16 +115,13 @@ def upload_files_to_space(repo_link, hf_token):
|
|
120 |
|
121 |
repo_url = f"https://huggingface.co/spaces/{user_name}/LangChain_{repo_name}Bot"
|
122 |
space_name = f"{user_name}/LangChain_{repo_name}Bot"
|
123 |
-
|
124 |
-
return "<p style='color: orange; text-align: center; font-size: 24px; background-color: lightgray;'>Successfully created the Chatbot at: <a href="+ repo_url + " target='_blank'>" + space_name + "</a></p>"
|
125 |
-
#<p style="color: orange; text-align: center; font-size: 24px; background-color: lightgray; display: inline-block;">This is some text</p>
|
126 |
|
127 |
|
128 |
def driver(repo_link, hf_token):
|
129 |
#create search index openai_api_key=openai_api_key
|
130 |
#search_index_pickle = create_search_index(repo_link, openai_api_key)
|
131 |
#create a new space
|
132 |
-
print("***********INSIDE DRIVER***************")
|
133 |
create_space(repo_link, hf_token)
|
134 |
#upload files to the new space
|
135 |
html_tag = upload_files_to_space(repo_link, hf_token)
|
@@ -155,11 +147,11 @@ with gr.Blocks() as demo:
|
|
155 |
</h1>
|
156 |
</div>
|
157 |
<p style="margin-bottom: 10px; font-size: 94%">
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
<a href="https://huggingface.co/spaces/ysharma/LangchainBot-space-creator?duplicate=true"><img src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>
|
163 |
</p>
|
164 |
</div>""")
|
165 |
with gr.Row() :
|
|
|
48 |
|
49 |
#Code for creating a new space for the user
|
50 |
def create_space(repo_link, hf_token):
|
|
|
51 |
repo_name = repo_link.split('/')[-1]
|
52 |
api = HfApi(token=hf_token)
|
53 |
repo_url = api.create_repo(
|
|
|
60 |
#Code for creating the search index
|
61 |
#Saving search index to disk
|
62 |
def create_search_index(repo_link, openai_api_key):
|
63 |
+
sources = get_github_docs(repo_link)
|
|
|
|
|
64 |
source_chunks = []
|
65 |
splitter = CharacterTextSplitter(separator=" ", chunk_size=1024, chunk_overlap=0)
|
66 |
for source in sources:
|
|
|
75 |
return "search_index.pickle"
|
76 |
|
77 |
def upload_files_to_space(repo_link, hf_token):
|
|
|
78 |
repo_name = repo_link.split('/')[-1]
|
79 |
api = HfApi(token=hf_token)
|
80 |
user_name = whoami(token=hf_token)['name']
|
|
|
83 |
with open("template/app_og.py", "r") as f:
|
84 |
app = f.read()
|
85 |
app = app.replace("$RepoName", repo_name)
|
|
|
86 |
|
87 |
#Saving the new app.py file to disk
|
88 |
with open("template/app.py", "w") as f:
|
|
|
115 |
|
116 |
repo_url = f"https://huggingface.co/spaces/{user_name}/LangChain_{repo_name}Bot"
|
117 |
space_name = f"{user_name}/LangChain_{repo_name}Bot"
|
118 |
+
return "<p style='color: orange; text-align: center; font-size: 24px; background-color: lightgray;'>🎉Congratulations🎉 Chatbot created successfully! Access it here : <a href="+ repo_url + " target='_blank'>" + space_name + "</a></p>"
|
|
|
|
|
119 |
|
120 |
|
121 |
def driver(repo_link, hf_token):
|
122 |
#create search index openai_api_key=openai_api_key
|
123 |
#search_index_pickle = create_search_index(repo_link, openai_api_key)
|
124 |
#create a new space
|
|
|
125 |
create_space(repo_link, hf_token)
|
126 |
#upload files to the new space
|
127 |
html_tag = upload_files_to_space(repo_link, hf_token)
|
|
|
147 |
</h1>
|
148 |
</div>
|
149 |
<p style="margin-bottom: 10px; font-size: 94%">
|
150 |
+
Generate a top-notch <b>Q&A Chatbot</b> for your Github Repo, using <a href="https://langchain.readthedocs.io/en/latest/" target="_blank">LangChain</a> and <a href="https://github.com/gradio-app/gradio" target="_blank">Gradio</a>.
|
151 |
+
Paste your Github repository link, enter your OpenAI API key, and the app will create a FAISS embedding vector space for you.
|
152 |
+
Next, input your Huggingface Token and press the final button.<br><br>
|
153 |
+
Your new chatbot will be ready under your Huggingface profile, accessible via the displayed link.
|
154 |
+
<center><a href="https://huggingface.co/spaces/ysharma/LangchainBot-space-creator?duplicate=true"><img src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a></center>
|
155 |
</p>
|
156 |
</div>""")
|
157 |
with gr.Row() :
|