Spaces:
Runtime error
Runtime error
Commit
·
099b6c0
1
Parent(s):
eebbcf7
Update app.py
Browse files
app.py
CHANGED
@@ -1,64 +1,46 @@
|
|
1 |
-
import
|
2 |
-
|
3 |
-
from
|
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 |
-
st.success(f"Found {len(repo_info)} repositories with the file '{filename}':")
|
48 |
-
for repo in repo_info:
|
49 |
-
st.write(f"- **{repo['name']}**: {repo['description']}")
|
50 |
-
st.write(f" URL: [{repo['url']}]({repo['url']})")
|
51 |
-
else:
|
52 |
-
logger.warning(f"No repositories found with the file '{filename}'.")
|
53 |
-
st.warning(f"No repositories found with the file '{filename}'.")
|
54 |
-
|
55 |
-
st.sidebar.title("GitHub File Search Options")
|
56 |
-
show_logs = st.sidebar.checkbox("Show Logs")
|
57 |
-
if show_logs:
|
58 |
-
st.sidebar.subheader("Logs")
|
59 |
-
with open("app.log", "r") as log_file:
|
60 |
-
logs = log_file.read()
|
61 |
-
st.sidebar.text(logs)
|
62 |
-
|
63 |
-
if __name__ == "__main__":
|
64 |
-
app()
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
4 |
+
|
5 |
+
# Initialize the CodeBERT model and tokenizer
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained("microsoft/CodeBERT-base")
|
7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("microsoft/CodeBERT-base")
|
8 |
+
|
9 |
+
def fetch_repo_contents(repo_url):
|
10 |
+
# Extract username and repo name from URL
|
11 |
+
username, repo_name = repo_url.split("github.com/")[-1].split("/")
|
12 |
+
|
13 |
+
# Fetch repo contents using GitHub API
|
14 |
+
api_url = f"https://api.github.com/repos/{username}/{repo_name}/contents"
|
15 |
+
response = requests.get(api_url)
|
16 |
+
response.raise_for_status()
|
17 |
+
return response.json()
|
18 |
+
|
19 |
+
def generate_chatbot_response(repo_url, question):
|
20 |
+
# Fetch repository contents
|
21 |
+
repo_contents = fetch_repo_contents(repo_url)
|
22 |
+
|
23 |
+
# Generate a prompt based on the user's question and repository contents
|
24 |
+
prompt = f"Answer the question about the repository {repo_url}: {question}\n\n"
|
25 |
+
for item in repo_contents:
|
26 |
+
prompt += f"{item['name']}:\n{item['download_url']}\n\n"
|
27 |
+
|
28 |
+
# Tokenize the prompt and generate a response using the CodeBERT model
|
29 |
+
inputs = tokenizer.encode(prompt, return_tensors="pt", max_length=1024, truncation=True)
|
30 |
+
outputs = model.generate(inputs, max_length=150, num_return_sequences=1)
|
31 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
32 |
+
|
33 |
+
return response
|
34 |
+
|
35 |
+
# Gradio UI
|
36 |
+
repo_url_input = gr.inputs.Textbox(lines=1, label="GitHub Repository URL")
|
37 |
+
question_input = gr.inputs.Textbox(lines=2, label="Question")
|
38 |
+
output_text = gr.outputs.Textbox(label="Answer")
|
39 |
+
|
40 |
+
gr.Interface(
|
41 |
+
generate_chatbot_response,
|
42 |
+
inputs=[repo_url_input, question_input],
|
43 |
+
outputs=output_text,
|
44 |
+
title="Create a Conversational AI Chatbot for Your Public GitHub Repository Codebase",
|
45 |
+
theme="huggingface_dark",
|
46 |
+
).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|