Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -9,8 +9,8 @@ load_dotenv()
|
|
9 |
image_API="https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-2"
|
10 |
translation_API="https://api-inference.huggingface.co/models/facebook/nllb-200-distilled-1.3B"
|
11 |
whisper_API="https://api-inference.huggingface.co/models/openai/whisper-large-v3"
|
12 |
-
txt_API="https://api-inference.huggingface.co/models/
|
13 |
-
HF_TOKEN=os.getenv("
|
14 |
login(HF_TOKEN)
|
15 |
headers={"Authorization":f"Bearer {HF_TOKEN}"}
|
16 |
|
@@ -49,8 +49,21 @@ def query_image(prompt):
|
|
49 |
time.sleep(delay)
|
50 |
return None
|
51 |
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
def process_audio(audio_path):
|
56 |
if not audio_path:
|
@@ -61,6 +74,7 @@ def process_audio(audio_path):
|
|
61 |
translation=query_translation(tamil_text)
|
62 |
translated_text=translation.get("translated_text","Translation error")
|
63 |
image_path=query_image(translated_text)
|
|
|
64 |
return tamil_text,translated_text,image_path
|
65 |
except Exception as e:
|
66 |
return None,str(e),None
|
|
|
9 |
image_API="https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-2"
|
10 |
translation_API="https://api-inference.huggingface.co/models/facebook/nllb-200-distilled-1.3B"
|
11 |
whisper_API="https://api-inference.huggingface.co/models/openai/whisper-large-v3"
|
12 |
+
txt_API="https://api-inference.huggingface.co/models/deepseek-ai/DeepSeek-R1"
|
13 |
+
HF_TOKEN=os.getenv("HF_TOKEN")
|
14 |
login(HF_TOKEN)
|
15 |
headers={"Authorization":f"Bearer {HF_TOKEN}"}
|
16 |
|
|
|
49 |
time.sleep(delay)
|
50 |
return None
|
51 |
|
52 |
+
def query_text_generation(prompt):
|
53 |
+
max_retries=5
|
54 |
+
delay=10
|
55 |
+
payload={"inputs":f"give me a short story about {prompt}"}
|
56 |
+
for attempt in range(max_retries):
|
57 |
+
response=requests.post(txt_API,headers=headers,json=payload)
|
58 |
+
if response.status_code == 200:
|
59 |
+
result=response.json()
|
60 |
+
if isinstance(result,list) and len(result)>0:
|
61 |
+
return result[0].get("generated_text","Text Generation Error")
|
62 |
+
elif isinstance(result,dict) and "generated_text" in result:
|
63 |
+
return result["generated_text"]
|
64 |
+
print(f"⚠️ Text generation failed, retrying in {delay} seconds...")
|
65 |
+
time.sleep(delay)
|
66 |
+
return None
|
67 |
|
68 |
def process_audio(audio_path):
|
69 |
if not audio_path:
|
|
|
74 |
translation=query_translation(tamil_text)
|
75 |
translated_text=translation.get("translated_text","Translation error")
|
76 |
image_path=query_image(translated_text)
|
77 |
+
story=query_text_generation(translated_text)
|
78 |
return tamil_text,translated_text,image_path
|
79 |
except Exception as e:
|
80 |
return None,str(e),None
|