Spaces:
Sleeping
Sleeping
Update: Add debug logs and fix model
Browse files
app.py
CHANGED
|
@@ -5,8 +5,10 @@ import time
|
|
| 5 |
from groq import Groq
|
| 6 |
from difflib import SequenceMatcher
|
| 7 |
|
| 8 |
-
# API
|
| 9 |
GROQ_API_KEY = os.environ.get("GROQ_API_KEY", "")
|
|
|
|
|
|
|
| 10 |
client = Groq(api_key=GROQ_API_KEY) if GROQ_API_KEY else None
|
| 11 |
|
| 12 |
# --- Dataset Loading ---
|
|
@@ -14,16 +16,13 @@ chat_db = []
|
|
| 14 |
try:
|
| 15 |
csv_url = "https://huggingface.co/datasets/amkyawdev/AmkyawDev-Dataset/raw/main/train.csv"
|
| 16 |
df = pd.read_csv(csv_url)
|
| 17 |
-
|
| 18 |
if not df.empty:
|
| 19 |
-
# Fix: Use 'input' and 'output' columns instead of index
|
| 20 |
for _, row in df.iterrows():
|
| 21 |
if 'input' in row and 'output' in row:
|
| 22 |
u_text = str(row['input']).strip()
|
| 23 |
a_text = str(row['output']).strip()
|
| 24 |
if u_text != "nan" and a_text != "nan" and u_text and a_text:
|
| 25 |
chat_db.append({"u": u_text, "a": a_text})
|
| 26 |
-
|
| 27 |
print(f"β
Dataset Sync: {len(chat_db)} pairs loaded.")
|
| 28 |
except Exception as e:
|
| 29 |
print(f"β οΈ Dataset Loading Warning: {e}")
|
|
@@ -66,6 +65,8 @@ def generate_response(user_input, history):
|
|
| 66 |
return
|
| 67 |
except Exception as e:
|
| 68 |
print(f"Groq Error: {e}")
|
|
|
|
|
|
|
| 69 |
|
| 70 |
# Priority 3: Fallback
|
| 71 |
yield "αα±α¬ααΊαΈαααΊαα«αααΊα α‘αα―αα±α¬αα±α¬αααΊ αααΌα±ααα―ααΊαα±αΈαα«αα°αΈαααΊαα»α¬α"
|
|
@@ -107,7 +108,7 @@ with gr.Blocks(title="Amkyaw AI") as demo:
|
|
| 107 |
<div class="header-card">
|
| 108 |
<div style="display:flex; justify-content: space-between; align-items: center;">
|
| 109 |
<div><b style="color: white; font-size: 24px;">π€ Amkyaw AI</b></div>
|
| 110 |
-
<div style="color:white; font-size:12px;">v4.
|
| 111 |
</div>
|
| 112 |
</div>
|
| 113 |
""")
|
|
@@ -132,4 +133,4 @@ with gr.Blocks(title="Amkyaw AI") as demo:
|
|
| 132 |
submit.click(user_flow, [msg, chatbot], [msg, chatbot], queue=False).then(bot_flow, chatbot, chatbot)
|
| 133 |
|
| 134 |
if __name__ == "__main__":
|
| 135 |
-
demo.launch(css=custom_css)
|
|
|
|
| 5 |
from groq import Groq
|
| 6 |
from difflib import SequenceMatcher
|
| 7 |
|
| 8 |
+
# Debug: Print API key status
|
| 9 |
GROQ_API_KEY = os.environ.get("GROQ_API_KEY", "")
|
| 10 |
+
print(f"GROQ_API_KEY loaded: {bool(GROQ_API_KEY)}")
|
| 11 |
+
|
| 12 |
client = Groq(api_key=GROQ_API_KEY) if GROQ_API_KEY else None
|
| 13 |
|
| 14 |
# --- Dataset Loading ---
|
|
|
|
| 16 |
try:
|
| 17 |
csv_url = "https://huggingface.co/datasets/amkyawdev/AmkyawDev-Dataset/raw/main/train.csv"
|
| 18 |
df = pd.read_csv(csv_url)
|
|
|
|
| 19 |
if not df.empty:
|
|
|
|
| 20 |
for _, row in df.iterrows():
|
| 21 |
if 'input' in row and 'output' in row:
|
| 22 |
u_text = str(row['input']).strip()
|
| 23 |
a_text = str(row['output']).strip()
|
| 24 |
if u_text != "nan" and a_text != "nan" and u_text and a_text:
|
| 25 |
chat_db.append({"u": u_text, "a": a_text})
|
|
|
|
| 26 |
print(f"β
Dataset Sync: {len(chat_db)} pairs loaded.")
|
| 27 |
except Exception as e:
|
| 28 |
print(f"β οΈ Dataset Loading Warning: {e}")
|
|
|
|
| 65 |
return
|
| 66 |
except Exception as e:
|
| 67 |
print(f"Groq Error: {e}")
|
| 68 |
+
yield f"Error: {str(e)}"
|
| 69 |
+
return
|
| 70 |
|
| 71 |
# Priority 3: Fallback
|
| 72 |
yield "αα±α¬ααΊαΈαααΊαα«αααΊα α‘αα―αα±α¬αα±α¬αααΊ αααΌα±ααα―ααΊαα±αΈαα«αα°αΈαααΊαα»α¬α"
|
|
|
|
| 108 |
<div class="header-card">
|
| 109 |
<div style="display:flex; justify-content: space-between; align-items: center;">
|
| 110 |
<div><b style="color: white; font-size: 24px;">π€ Amkyaw AI</b></div>
|
| 111 |
+
<div style="color:white; font-size:12px;">v4.2 | 8B Model</div>
|
| 112 |
</div>
|
| 113 |
</div>
|
| 114 |
""")
|
|
|
|
| 133 |
submit.click(user_flow, [msg, chatbot], [msg, chatbot], queue=False).then(bot_flow, chatbot, chatbot)
|
| 134 |
|
| 135 |
if __name__ == "__main__":
|
| 136 |
+
demo.launch(css=custom_css)
|