Update app.py
Browse files
app.py
CHANGED
@@ -18,13 +18,6 @@ CHATBOT_SYSTEM_PROMPT = """You are a helpful AI assistant that analyzes Hugging
|
|
18 |
Your task is to help users understand repositories, extract key information, and provide insights.
|
19 |
Be concise, clear, and focus on the most important aspects of each repository."""
|
20 |
|
21 |
-
class AppState:
|
22 |
-
"""Simple state management for the application."""
|
23 |
-
def __init__(self):
|
24 |
-
self.repo_ids: List[str] = []
|
25 |
-
self.current_repo_idx: int = 0
|
26 |
-
self.chat_history: List[Dict[str, str]] = []
|
27 |
-
|
28 |
def read_csv_as_text(filename: str) -> pd.DataFrame:
|
29 |
"""Read CSV file and return as DataFrame."""
|
30 |
try:
|
@@ -78,10 +71,9 @@ def analyze_repo(repo_id: str) -> Tuple[str, str]:
|
|
78 |
logger.error(f"Error analyzing repo {repo_id}: {e}")
|
79 |
return f"Error analyzing {repo_id}", f"Error: {str(e)}"
|
80 |
|
81 |
-
def chat_with_user(message: str, history: List[Dict[str, str]]
|
82 |
"""Simple chat response."""
|
83 |
try:
|
84 |
-
# For now, return a simple response
|
85 |
return f"I understand you're asking about: {message}. How can I help you analyze this repository?"
|
86 |
except Exception as e:
|
87 |
logger.error(f"Error in chat: {e}")
|
@@ -89,8 +81,6 @@ def chat_with_user(message: str, history: List[Dict[str, str]], system_prompt: s
|
|
89 |
|
90 |
def create_ui() -> gr.Blocks:
|
91 |
"""Create a simplified Gradio interface."""
|
92 |
-
state = gr.State(AppState())
|
93 |
-
|
94 |
with gr.Blocks(title="Hugging Face Repo Analyzer", theme=gr.themes.Soft()) as app:
|
95 |
gr.Markdown("# Hugging Face Repository Analyzer")
|
96 |
|
@@ -117,13 +107,17 @@ def create_ui() -> gr.Blocks:
|
|
117 |
summary_output = gr.Textbox(label="Analysis Summary", lines=5)
|
118 |
|
119 |
# Chat Section
|
120 |
-
chatbot = gr.Chatbot(
|
|
|
|
|
|
|
|
|
121 |
msg = gr.Textbox(label="Message", placeholder="Ask about the repository...")
|
122 |
with gr.Row():
|
123 |
send_btn = gr.Button("Send", variant="primary")
|
124 |
clear_btn = gr.Button("Clear Chat", variant="secondary")
|
125 |
|
126 |
-
def process_input(text: str
|
127 |
"""Process input and return results."""
|
128 |
try:
|
129 |
# Check if input is keywords or repo IDs
|
@@ -143,9 +137,7 @@ def create_ui() -> gr.Blocks:
|
|
143 |
if not repo_ids:
|
144 |
return pd.DataFrame(), "No repositories found", "", ""
|
145 |
|
146 |
-
# Update
|
147 |
-
state.repo_ids = repo_ids
|
148 |
-
state.current_repo_idx = 0
|
149 |
write_repos_to_csv(repo_ids)
|
150 |
|
151 |
# Get first repo analysis
|
@@ -157,12 +149,12 @@ def create_ui() -> gr.Blocks:
|
|
157 |
logger.error(f"Error processing input: {e}")
|
158 |
return pd.DataFrame(), f"Error: {str(e)}", "", ""
|
159 |
|
160 |
-
def send_message(message: str, history: List[Dict[str, str]]
|
161 |
"""Send message to chat."""
|
162 |
if not message:
|
163 |
return history, ""
|
164 |
history.append({"role": "user", "content": message})
|
165 |
-
response = chat_with_user(message, history
|
166 |
history.append({"role": "assistant", "content": response})
|
167 |
return history, ""
|
168 |
|
@@ -173,13 +165,13 @@ def create_ui() -> gr.Blocks:
|
|
173 |
# Event handlers
|
174 |
submit_btn.click(
|
175 |
fn=process_input,
|
176 |
-
inputs=[repo_input
|
177 |
outputs=[df_output, status, content_output, summary_output]
|
178 |
)
|
179 |
|
180 |
send_btn.click(
|
181 |
fn=send_message,
|
182 |
-
inputs=[msg, chatbot
|
183 |
outputs=[chatbot, msg]
|
184 |
)
|
185 |
|
|
|
18 |
Your task is to help users understand repositories, extract key information, and provide insights.
|
19 |
Be concise, clear, and focus on the most important aspects of each repository."""
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
def read_csv_as_text(filename: str) -> pd.DataFrame:
|
22 |
"""Read CSV file and return as DataFrame."""
|
23 |
try:
|
|
|
71 |
logger.error(f"Error analyzing repo {repo_id}: {e}")
|
72 |
return f"Error analyzing {repo_id}", f"Error: {str(e)}"
|
73 |
|
74 |
+
def chat_with_user(message: str, history: List[Dict[str, str]]) -> str:
|
75 |
"""Simple chat response."""
|
76 |
try:
|
|
|
77 |
return f"I understand you're asking about: {message}. How can I help you analyze this repository?"
|
78 |
except Exception as e:
|
79 |
logger.error(f"Error in chat: {e}")
|
|
|
81 |
|
82 |
def create_ui() -> gr.Blocks:
|
83 |
"""Create a simplified Gradio interface."""
|
|
|
|
|
84 |
with gr.Blocks(title="Hugging Face Repo Analyzer", theme=gr.themes.Soft()) as app:
|
85 |
gr.Markdown("# Hugging Face Repository Analyzer")
|
86 |
|
|
|
107 |
summary_output = gr.Textbox(label="Analysis Summary", lines=5)
|
108 |
|
109 |
# Chat Section
|
110 |
+
chatbot = gr.Chatbot(
|
111 |
+
label="Chat with Assistant",
|
112 |
+
height=400,
|
113 |
+
type="messages"
|
114 |
+
)
|
115 |
msg = gr.Textbox(label="Message", placeholder="Ask about the repository...")
|
116 |
with gr.Row():
|
117 |
send_btn = gr.Button("Send", variant="primary")
|
118 |
clear_btn = gr.Button("Clear Chat", variant="secondary")
|
119 |
|
120 |
+
def process_input(text: str) -> Tuple[pd.DataFrame, str, str, str]:
|
121 |
"""Process input and return results."""
|
122 |
try:
|
123 |
# Check if input is keywords or repo IDs
|
|
|
137 |
if not repo_ids:
|
138 |
return pd.DataFrame(), "No repositories found", "", ""
|
139 |
|
140 |
+
# Update CSV
|
|
|
|
|
141 |
write_repos_to_csv(repo_ids)
|
142 |
|
143 |
# Get first repo analysis
|
|
|
149 |
logger.error(f"Error processing input: {e}")
|
150 |
return pd.DataFrame(), f"Error: {str(e)}", "", ""
|
151 |
|
152 |
+
def send_message(message: str, history: List[Dict[str, str]]) -> Tuple[List[Dict[str, str]], str]:
|
153 |
"""Send message to chat."""
|
154 |
if not message:
|
155 |
return history, ""
|
156 |
history.append({"role": "user", "content": message})
|
157 |
+
response = chat_with_user(message, history)
|
158 |
history.append({"role": "assistant", "content": response})
|
159 |
return history, ""
|
160 |
|
|
|
165 |
# Event handlers
|
166 |
submit_btn.click(
|
167 |
fn=process_input,
|
168 |
+
inputs=[repo_input],
|
169 |
outputs=[df_output, status, content_output, summary_output]
|
170 |
)
|
171 |
|
172 |
send_btn.click(
|
173 |
fn=send_message,
|
174 |
+
inputs=[msg, chatbot],
|
175 |
outputs=[chatbot, msg]
|
176 |
)
|
177 |
|