Spaces:
Running
Running
Krish Patel
commited on
Commit
·
df7ee24
1
Parent(s):
c37cf7b
Fixed return NULL issue from gemini
Browse files
app.py
CHANGED
@@ -44,7 +44,7 @@ def generate_knowledge_graph_viz(text, nlp, tokenizer, model):
|
|
44 |
|
45 |
# Randomly select subset of edges (e.g. 60% of edges)
|
46 |
edges = list(kg_builder.knowledge_graph.edges())
|
47 |
-
selected_edges = random.sample(edges, k=int(len(edges) * 0.
|
48 |
|
49 |
# Create a new graph with selected edges
|
50 |
selected_graph = nx.DiGraph()
|
@@ -140,14 +140,37 @@ def main():
|
|
140 |
update_knowledge_graph(news_text, ml_prediction == "REAL", knowledge_graph, nlp)
|
141 |
|
142 |
# Get Gemini analysis
|
143 |
-
|
144 |
-
|
|
|
|
|
145 |
|
146 |
-
|
147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
|
149 |
# Display metrics in columns
|
150 |
-
col1
|
151 |
|
152 |
with col1:
|
153 |
st.subheader("ML Model and Knowedge Graph Analysis")
|
@@ -159,12 +182,12 @@ def main():
|
|
159 |
# st.metric("Prediction", kg_prediction)
|
160 |
# st.metric("Confidence", f"{kg_confidence:.2f}%")
|
161 |
|
162 |
-
with
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
|
169 |
# Single expander for all analysis details
|
170 |
with st.expander("Detailed Analysis"):
|
|
|
44 |
|
45 |
# Randomly select subset of edges (e.g. 60% of edges)
|
46 |
edges = list(kg_builder.knowledge_graph.edges())
|
47 |
+
selected_edges = random.sample(edges, k=int(len(edges) * 0.3))
|
48 |
|
49 |
# Create a new graph with selected edges
|
50 |
selected_graph = nx.DiGraph()
|
|
|
140 |
update_knowledge_graph(news_text, ml_prediction == "REAL", knowledge_graph, nlp)
|
141 |
|
142 |
# Get Gemini analysis
|
143 |
+
# Get Gemini analysis with retries
|
144 |
+
max_retries = 3
|
145 |
+
retry_count = 0
|
146 |
+
gemini_result = None
|
147 |
|
148 |
+
while retry_count < max_retries:
|
149 |
+
try:
|
150 |
+
gemini_model = setup_gemini()
|
151 |
+
gemini_result = analyze_content_gemini(gemini_model, news_text)
|
152 |
+
|
153 |
+
# Check if we got valid results
|
154 |
+
if gemini_result and gemini_result.get('gemini_analysis'):
|
155 |
+
break
|
156 |
+
|
157 |
+
except Exception:
|
158 |
+
pass
|
159 |
+
|
160 |
+
retry_count += 1
|
161 |
+
|
162 |
+
# Use default values if all retries failed
|
163 |
+
if not gemini_result:
|
164 |
+
gemini_result = {
|
165 |
+
"gemini_analysis": {
|
166 |
+
"predicted_classification": "UNCERTAIN",
|
167 |
+
"confidence_score": "50",
|
168 |
+
"reasoning": ["Analysis temporarily unavailable"]
|
169 |
+
}
|
170 |
+
}
|
171 |
|
172 |
# Display metrics in columns
|
173 |
+
col1 = st.columns(1)
|
174 |
|
175 |
with col1:
|
176 |
st.subheader("ML Model and Knowedge Graph Analysis")
|
|
|
182 |
# st.metric("Prediction", kg_prediction)
|
183 |
# st.metric("Confidence", f"{kg_confidence:.2f}%")
|
184 |
|
185 |
+
# with col3:
|
186 |
+
# st.subheader("Gemini Analysis")
|
187 |
+
# gemini_pred = gemini_result["gemini_analysis"]["predicted_classification"]
|
188 |
+
# gemini_conf = gemini_result["gemini_analysis"]["confidence_score"]
|
189 |
+
# st.metric("Prediction", gemini_pred)
|
190 |
+
# st.metric("Confidence", f"{gemini_conf}%")
|
191 |
|
192 |
# Single expander for all analysis details
|
193 |
with st.expander("Detailed Analysis"):
|