before lines
This commit is contained in:
parent
bdef75118b
commit
be0eebd98e
24
nikud.py
24
nikud.py
|
@ -11,7 +11,9 @@ load_dotenv()
|
||||||
# Read API key from .env file
|
# Read API key from .env file
|
||||||
api_key = os.getenv("API_KEY")
|
api_key = os.getenv("API_KEY")
|
||||||
|
|
||||||
font = ImageFont.truetype("fonts/BonaNova-Regular.ttf", 40)
|
# Specify the font size
|
||||||
|
font_size = 40
|
||||||
|
font = ImageFont.truetype("fonts/BonaNova-Regular.ttf", font_size)
|
||||||
|
|
||||||
|
|
||||||
def get_nakdan_response(hebrew_text, api_key):
|
def get_nakdan_response(hebrew_text, api_key):
|
||||||
|
@ -23,7 +25,7 @@ def get_nakdan_response(hebrew_text, api_key):
|
||||||
"genre": "modern", # or "rabbinic" or "premodern" based on user's need
|
"genre": "modern", # or "rabbinic" or "premodern" based on user's need
|
||||||
"data": hebrew_text,
|
"data": hebrew_text,
|
||||||
"addmorph": True,
|
"addmorph": True,
|
||||||
"matchpartial": True,
|
"matchpartial": True,
|
||||||
"keepmetagim": False,
|
"keepmetagim": False,
|
||||||
"keepqq": False,
|
"keepqq": False,
|
||||||
"apiKey": api_key
|
"apiKey": api_key
|
||||||
|
@ -41,7 +43,7 @@ def main():
|
||||||
# Button to send request
|
# Button to send request
|
||||||
if st.button("Process Text"):
|
if st.button("Process Text"):
|
||||||
response = get_nakdan_response(hebrew_text, api_key)
|
response = get_nakdan_response(hebrew_text, api_key)
|
||||||
st.json(response)
|
# st.json(response)
|
||||||
# Extract words
|
# Extract words
|
||||||
words = [
|
words = [
|
||||||
option['w'].replace("|", "")
|
option['w'].replace("|", "")
|
||||||
|
@ -49,21 +51,25 @@ def main():
|
||||||
if 'nakdan' in item
|
if 'nakdan' in item
|
||||||
for option in item['nakdan'].get('options', [])
|
for option in item['nakdan'].get('options', [])
|
||||||
]
|
]
|
||||||
st.text(words)
|
st.text(" ".join(words)) # Print words after each other
|
||||||
|
|
||||||
# Create an image
|
# Create an image
|
||||||
img = Image.new('RGB', (300, 400), color=(255, 255, 255))
|
img_width = 696
|
||||||
|
img_height = 400 # font_size * (len(words) // 10 + 2) # Adjust the multiplier as needed
|
||||||
|
img = Image.new('RGB', (img_width, img_height), color=(255, 255, 255))
|
||||||
d = ImageDraw.Draw(img)
|
d = ImageDraw.Draw(img)
|
||||||
|
|
||||||
# Position for the first word
|
# Position for the first word
|
||||||
x, y = 10, 40
|
x, y = 10, 0
|
||||||
|
|
||||||
# Write words on the image
|
|
||||||
for word in words:
|
for word in words:
|
||||||
bidi_word = get_display(word) # Convert word to RTL format
|
bidi_word = get_display(word) # Convert word to RTL format
|
||||||
d.text((x, y), bidi_word, fill=(0, 0, 0), font=font)
|
d.text((x, y), bidi_word, fill=(0, 0, 0), font=font)
|
||||||
y += 45 # Move to the next line
|
st.text(f"Word: '{bidi_word}', Position: (x={x}, y={y}), {len(bidi_word)} characters")
|
||||||
|
y += 40 # Move to the next line
|
||||||
|
|
||||||
st.image(img)
|
st.image(img)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
BIN
pefectFake.jpg
BIN
pefectFake.jpg
Binary file not shown.
Before Width: | Height: | Size: 20 KiB |
6
readme
6
readme
|
@ -13,10 +13,12 @@ if you use a webcam try
|
||||||
```bash
|
```bash
|
||||||
sudo apt install fswebcam
|
sudo apt install fswebcam
|
||||||
```
|
```
|
||||||
|
### Fonts
|
||||||
|
im using google fonts, you can download them from [here](https://fonts.google.com/?subset=hebrew¬o.script=Hebr) and put that `.ttf` file in `fonts/`
|
||||||
|
|
||||||
### run
|
### Run
|
||||||
```bash
|
```bash
|
||||||
python txt.py
|
streamlit run txt.py
|
||||||
```
|
```
|
||||||
i usually add a tmux session to `~/.bashrc` to run the script on startup
|
i usually add a tmux session to `~/.bashrc` to run the script on startup
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user