ZeeAI1 commited on
Commit
770cb3e
·
verified ·
1 Parent(s): 1c498c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -36
app.py CHANGED
@@ -1,20 +1,3 @@
1
- import streamlit as st
2
- from transformers import pipeline
3
- import requests
4
-
5
- # Translation Pipelines
6
- translator_ur_en = pipeline("translation", model="Helsinki-NLP/opus-mt-ur-en")
7
- translator_en_ur = pipeline("translation", model="Helsinki-NLP/opus-mt-en-ur")
8
-
9
- # Hugging Face API Setup
10
- HF_API_TOKEN = "YOUR_HF_API_KEY" # Replace with your token from https://huggingface.co/settings/tokens
11
- DEEPSEEK_MODEL = "deepseek-ai/deepseek-llm-7b-chat"
12
-
13
- headers = {
14
- "Authorization": f"Bearer {HF_API_TOKEN}",
15
- "Content-Type": "application/json"
16
- }
17
-
18
  def query_deepseek(prompt):
19
  payload = {
20
  "inputs": f"<|system|>You are a helpful assistant.<|user|>{prompt}<|assistant|>",
@@ -25,23 +8,12 @@ def query_deepseek(prompt):
25
  headers=headers,
26
  json=payload
27
  )
28
- result = response.json()
29
- return result[0]["generated_text"].split("<|assistant|>")[-1].strip()
30
-
31
- # Streamlit UI
32
- st.title("🤖 Urdu AI Assistant (Powered by DeepSeek)")
33
-
34
- urdu_input = st.text_area("اپنا سوال اردو میں لکھیں:", height=100)
35
-
36
- if st.button("جواب حاصل کریں"):
37
- with st.spinner("ترجمہ ہو رہا ہے..."):
38
- english_prompt = translator_ur_en(urdu_input)[0]['translation_text']
39
 
40
- with st.spinner("DeepSeek سے جواب حاصل کیا جا رہا ہے..."):
41
- english_response = query_deepseek(english_prompt)
42
-
43
- with st.spinner("جواب اردو میں ترجمہ ہو رہا ہے..."):
44
- urdu_response = translator_en_ur(english_response)[0]['translation_text']
45
-
46
- st.markdown("### 📝 جواب:")
47
- st.write(urdu_response)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  def query_deepseek(prompt):
2
  payload = {
3
  "inputs": f"<|system|>You are a helpful assistant.<|user|>{prompt}<|assistant|>",
 
8
  headers=headers,
9
  json=payload
10
  )
 
 
 
 
 
 
 
 
 
 
 
11
 
12
+ try:
13
+ result = response.json()
14
+ # Debug output if response is not a list
15
+ if isinstance(result, dict) and "error" in result:
16
+ return f"⚠️ DeepSeek API error: {result['error']}"
17
+ return result[0]["generated_text"].split("<|assistant|>")[-1].strip()
18
+ except Exception as e:
19
+ return f"⚠️ Failed to parse DeepSeek response: {e}"