Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +61 -0
- requirements.txt +57 -0
app.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import requests
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
API_URL = "https://cm7kxsqi3sekfih7.us-east-1.aws.endpoints.huggingface.cloud"
|
| 7 |
+
headers = {
|
| 8 |
+
"Accept" : "application/json",
|
| 9 |
+
"Content-Type": "application/json"
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
def query(payload):
|
| 13 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
| 14 |
+
if response.status_code != 200:
|
| 15 |
+
print('Sleeping due to API error')
|
| 16 |
+
time.sleep(18)
|
| 17 |
+
return None
|
| 18 |
+
return response.json()
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def run_model(text):
|
| 22 |
+
output = query({
|
| 23 |
+
"inputs": text,
|
| 24 |
+
"parameters": {}
|
| 25 |
+
})
|
| 26 |
+
return output[0]['generated_text'] if output is not None else None
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
run_model('السلام عيكم')
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
import gradio as gr
|
| 39 |
+
|
| 40 |
+
examples = [
|
| 41 |
+
["ما ابغا أروح الإمتحان"],
|
| 42 |
+
["أييد أن انام ف لبيتنا"],
|
| 43 |
+
["Hello how are you today"]
|
| 44 |
+
]
|
| 45 |
+
|
| 46 |
+
def mode_run(text):
|
| 47 |
+
result = run_model(text)
|
| 48 |
+
if result:
|
| 49 |
+
return result
|
| 50 |
+
else:
|
| 51 |
+
return "Model is running please try again..."
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
demo = gr.Interface(fn=mode_run,
|
| 55 |
+
inputs="text",
|
| 56 |
+
outputs="text",
|
| 57 |
+
examples=examples)
|
| 58 |
+
|
| 59 |
+
demo.launch()
|
| 60 |
+
|
| 61 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
aiofiles==23.2.1
|
| 2 |
+
annotated-types==0.7.0
|
| 3 |
+
anyio==4.4.0
|
| 4 |
+
certifi==2024.8.30
|
| 5 |
+
charset-normalizer==3.3.2
|
| 6 |
+
click==8.1.7
|
| 7 |
+
contourpy==1.3.0
|
| 8 |
+
cycler==0.12.1
|
| 9 |
+
fastapi==0.112.2
|
| 10 |
+
ffmpy==0.4.0
|
| 11 |
+
filelock==3.15.4
|
| 12 |
+
fonttools==4.53.1
|
| 13 |
+
fsspec==2024.6.1
|
| 14 |
+
gradio==4.42.0
|
| 15 |
+
gradio_client==1.3.0
|
| 16 |
+
h11==0.14.0
|
| 17 |
+
httpcore==1.0.5
|
| 18 |
+
httpx==0.27.2
|
| 19 |
+
huggingface-hub==0.24.6
|
| 20 |
+
idna==3.8
|
| 21 |
+
importlib_resources==6.4.4
|
| 22 |
+
Jinja2==3.1.4
|
| 23 |
+
kiwisolver==1.4.5
|
| 24 |
+
markdown-it-py==3.0.0
|
| 25 |
+
MarkupSafe==2.1.5
|
| 26 |
+
matplotlib==3.9.2
|
| 27 |
+
mdurl==0.1.2
|
| 28 |
+
numpy==2.1.0
|
| 29 |
+
orjson==3.10.7
|
| 30 |
+
packaging==24.1
|
| 31 |
+
pandas==2.2.2
|
| 32 |
+
pillow==10.4.0
|
| 33 |
+
pydantic==2.8.2
|
| 34 |
+
pydantic_core==2.20.1
|
| 35 |
+
pydub==0.25.1
|
| 36 |
+
Pygments==2.18.0
|
| 37 |
+
pyparsing==3.1.4
|
| 38 |
+
python-dateutil==2.9.0.post0
|
| 39 |
+
python-multipart==0.0.9
|
| 40 |
+
pytz==2024.1
|
| 41 |
+
PyYAML==6.0.2
|
| 42 |
+
requests==2.32.3
|
| 43 |
+
rich==13.8.0
|
| 44 |
+
ruff==0.6.3
|
| 45 |
+
semantic-version==2.10.0
|
| 46 |
+
shellingham==1.5.4
|
| 47 |
+
six==1.16.0
|
| 48 |
+
sniffio==1.3.1
|
| 49 |
+
starlette==0.38.2
|
| 50 |
+
tomlkit==0.12.0
|
| 51 |
+
tqdm==4.66.5
|
| 52 |
+
typer==0.12.5
|
| 53 |
+
typing_extensions==4.12.2
|
| 54 |
+
tzdata==2024.1
|
| 55 |
+
urllib3==2.2.2
|
| 56 |
+
uvicorn==0.30.6
|
| 57 |
+
websockets==12.0
|