Spaces:
Sleeping
Sleeping
File size: 138,348 Bytes
ca7e2c7 7d226eb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 |
import streamlit as st
from streamlit_option_menu import option_menu
from streamlit_chat import message
import openai
# from openai import OpenAI
import requests
import json
import streamlit.components.v1 as components
import webbrowser
import pickle
import random
from streamlit_pills import pills
from pathlib import Path
from streamlit_login_auth_ui.widgets import __login__
from streamlit_lottie import st_lottie
from typing import Optional, Any, Dict, List
from PIL import Image, ImageEnhance
from rembg import remove
from datetime import datetime, timedelta
import os
import gtts
from datetime import datetime
from gtts import gTTS
from googletrans import Translator
import urllib.request
import time
import warnings
warnings.filterwarnings("ignore")
# PPT Imports
import streamlit as st
# import plotly.express as px
from pptx import Presentation
from pptx.util import Inches
from datetime import date
import requests
from io import BytesIO
import glob
import base64
import os
import random
# import codecs
import re
import string
from datetime import datetime
import string
from pathlib import Path
import subprocess
from pptx.dml.color import RGBColor
import yaml
from yaml.loader import SafeLoader
# End of PPT Imports
# langchain methods and imports
from langchain import LLMChain, OpenAI
from langchain.agents import AgentExecutor, Tool, ZeroShotAgent
from langchain.chains import RetrievalQA
from langchain.chains.question_answering import load_qa_chain
from langchain.docstore.document import Document
from langchain.document_loaders import PyPDFLoader
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.llms import OpenAI
from langchain.memory import ConversationBufferMemory
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.vectorstores import VectorStore
from langchain.vectorstores.faiss import FAISS
from pypdf import PdfReader
# Define a function to parse a PDF file and extract its text content
@st.cache_data
def parse_pdf(file: BytesIO) -> List[str]:
pdf = PdfReader(file)
output = []
for page in pdf.pages:
text = page.extract_text()
# Merge hyphenated words
text = re.sub(r"(\w+)-\n(\w+)", r"\1\2", text)
# Fix newlines in the middle of sentences
text = re.sub(r"(?<!\n\s)\n(?!\s\n)", " ", text.strip())
# Remove multiple newlines
text = re.sub(r"\n\s*\n", "\n\n", text)
output.append(text)
return output
# Define a function to convert text content to a list of documents
@st.cache_data
def text_to_docs(text: str) -> List[Document]:
"""Converts a string or list of strings to a list of Documents
with metadata."""
if isinstance(text, str):
# Take a single string as one page
text = [text]
page_docs = [Document(page_content=page) for page in text]
# Add page numbers as metadata
for i, doc in enumerate(page_docs):
doc.metadata["page"] = i + 1
# Split pages into chunks
doc_chunks = []
for doc in page_docs:
text_splitter = RecursiveCharacterTextSplitter(
chunk_size=2000,
separators=["\n\n", "\n", ".", "!", "?", ",", " ", ""],
chunk_overlap=0,
)
chunks = text_splitter.split_text(doc.page_content)
for i, chunk in enumerate(chunks):
doc = Document(
page_content=chunk, metadata={"page": doc.metadata["page"], "chunk": i}
)
# Add sources a metadata
doc.metadata["source"] = f"{doc.metadata['page']}-{doc.metadata['chunk']}"
doc_chunks.append(doc)
return doc_chunks
# Define a function for the embeddings
@st.cache_data
def test_embed():
embeddings = OpenAIEmbeddings(openai_api_key=api)
# Indexing
# Save in a Vector DB
with st.spinner("It's indexing..."):
index = FAISS.from_documents(pages, embeddings)
st.success("Embeddings done.", icon="β
")
return index
# End of langchain methods
import pandas as pd
df = pd.read_csv('files.csv')
# Load OpenAI key
# openai.api_key = open_api_key
# from sd2.generate import PIPELINE_NAMES, generate
# DEFAULT_PROMPT = "border collie puppy"
# DEFAULT_WIDTH, DEFAULT_HEIGHT = 512, 512
# OUTPUT_IMAGE_KEY = "output_img"
# LOADED_IMAGE_KEY = "loaded_image"
# For simple chat module
def get_initial_message():
messages=[
{"role": "system", "content": "You are a helpful AI Assistant created by Alpha AI. You can do anything."},
{"role": "user", "content": "I want to know a lot of things."},
{"role": "assistant", "content": "Thats awesome, what do you want to know about."}
]
return messages
def get_chatgpt_response(messages, model="gpt-4o"):
print("model: ", model)
response = openai.ChatCompletion.create(
model=model,
messages=messages
)
return response['choices'][0]['message']['content']
def update_chat(messages, role, content):
messages.append({"role": role, "content": content})
return messages
# ------
# Define image sizes
image_sizes = {
"256x256": "256x256",
"512x512": "512x512",
"1024x1024": "1024x1024"
}
# For making AD copies
# Define function to generate image
def generate_image_edit_dalle(prompt, size,input_img,mask_img):
outline_img = "A high resolution portrait of " + prompt
img_response = openai.Image.create_edit(
image=open(input_img, "rb"),
mask=open(mask_img, "rb"),
prompt=outline_img,
n=1,
size=size
)
image_url = img_response['data'][0]['url']
urllib.request.urlretrieve(image_url, 'img_dalle_inp.png')
img = Image.open("img_dalle_inp.png")
return img
# Define function to generate image
def generate_image(prompt, size):
outline_img = "A high resolution portrait of "
img_response = openai.Image.create(
prompt=prompt,
n=1,
size=size)
img_url = img_response['data'][0]['url']
urllib.request.urlretrieve(img_url, 'img.png')
img = Image.open("img.png")
return img
# Text to Speech Avatars
def text_to_speech_avatar(text):
tts = gTTS(text, lang='en', tld='co.uk', slow=False)
# try:
# my_file_name = text[0:20]
# except:
# my_file_name = "audio"
addition_name = st.session_state['name'][:5]
my_file_name = "dummy_" + addition_name
tts.save(f"temp/{my_file_name}.mp3")
# print(my_file_name)
return True
# PPT Methods
bad_coding_practice = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in
range(16))
def refresh_bad_coding_practice():
global bad_coding_practice
bad_coding_practice = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits)
for _ in range(16))
return
def generate_content_blog(user_input):
completion = openai.ChatCompletion.create(model="gpt-4o", messages=[
{"role": "system", "content": "You are an expert blog writer and can produce perfect grammar, sentence formation and SEO capable blogs."},
{"role": "user", "content": user_input}
],max_tokens=2500, temperature = 0.6,presence_penalty = 0.1,frequency_penalty = 0.1,top_p=1,)
result = completion.choices[0].message.content
return result
def PrefixNameDownloader(image_description):
outline_img = "A high resolution image of "
img_response = openai.Image.create(
prompt = outline_img + image_description,
n=1,
size="512x512")
img_url = img_response['data'][0]['url']
img_name = 'prefix_' + bad_coding_practice + "img001.jpg"
urllib.request.urlretrieve(img_url, img_name)
# img = Image.open("img.png")
return img_name
def generate_ppt(topic, slide_length,color, font_colors):
root = Presentation("theme0.pptx")
message = f"""Create a slideshow presentation on the topic of {topic} which is {slide_length} slides
long. Add images on every slide except the title slide.
You are allowed to use the following slide types:
Slide types:
Title Slide - (Title, Subtitle)
Content Slide - (Title, Content)
Image Slide - (Title, Content, Image)
Thanks Slide - (Title)
Put this tag before the Title Slide: [L_TS]
Put this tag before the Content Slide: [L_CS]
Put this tag before the Image Slide: [L_IS]
Put this tag before the Thanks Slide: [L_THS]
Put "[SLIDEBREAK]" after each slide
For example:
[L_TS]
[TITLE]Mental Health[/TITLE]
[SLIDEBREAK]
[L_CS]
[TITLE]Mental Health Definition[/TITLE]
[CONTENT]
1. Definition: A personβs condition with regard to their psychological and emotional well-being
2. Can impact one's physical health
3. Stigmatized too often.
[/CONTENT]
[SLIDEBREAK]
Put this tag before the Title: [TITLE]
Put this tag after the Title: [/TITLE]
Put this tag before the Subitle: [SUBTITLE]
Put this tag after the Subtitle: [/SUBTITLE]
Put this tag before the Content: [CONTENT]
Put this tag after the Content: [/CONTENT]
Put this tag before the Image: [IMAGE]
Put this tag after the Image: [/IMAGE]
Elaborate on the Content, provide as much information as possible.
You put a [/CONTENT] at the end of the Content.
Do not reply as if you are talking about the slideshow itself. (ex. "Include pictures here about...")
Do not include any special characters (?, !, ., :, ) in the Title.
Do not include any additional information in your response and stick to the format."""
response = openai.ChatCompletion.create(
model="gpt-4o",
messages=[
{
"role": "system", "content": "Act as an expert presentation creator. You know all about designs, creativity, layouts and how to make amazing presentations",
"role": "user", "content": message
}
]
)
# """ Ref for slide types:
# 0 -> title and subtitle
# 1 -> title and content
# 2 -> section header
# 3 -> two content
# 4 -> Comparison
# 5 -> Title only
# 6 -> Blank
# 7 -> Content with caption
# 8 -> Pic with caption
# """
def delete_all_slides():
for i in range(len(root.slides)-1, -1, -1):
r_id = root.slides._sldIdLst[i].rId
root.part.drop_rel(r_id)
del root.slides._sldIdLst[i]
def create_title_slide(title, subtitle,slide_bg_color, font_colors):
layout = root.slide_layouts[0]
slide = root.slides.add_slide(layout)
background = slide.background
if slide_bg_color == "white":
background.fill.solid()
background.fill.fore_color.rgb = RGBColor(255, 255, 255)
elif slide_bg_color == "black":
background.fill.solid()
background.fill.fore_color.rgb = RGBColor(0, 0, 0)
elif slide_bg_color == "red":
background.fill.solid()
background.fill.fore_color.rgb = RGBColor(255, 0, 0)
elif slide_bg_color == "green":
background.fill.solid()
background.fill.fore_color.rgb = RGBColor(0, 255, 0)
elif slide_bg_color == "blue":
background.fill.solid()
background.fill.fore_color.rgb = RGBColor(0, 0, 255)
else:
# If an invalid color is provided, default to white
background.fill.solid()
background.fill.fore_color.rgb = RGBColor(255, 255, 255)
slide.shapes.title.text = title
slide.placeholders[1].text = subtitle
if font_colors == "white":
# slide.shapes.title.font.color.rgb = RGBColor(255, 255, 255)
slide.shapes.title.text_frame.paragraphs[0].font.color.rgb = RGBColor(255, 255, 255)
slide.placeholders[1].text_frame.paragraphs[0].font.color.rgb = RGBColor(255, 255, 255)
elif font_colors == "black":
slide.shapes.title.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 0, 0)
slide.placeholders[1].text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 0, 0)
elif font_colors == "red":
slide.shapes.title.text_frame.paragraphs[0].font.color.rgb = RGBColor(255, 0, 0)
slide.placeholders[1].text_frame.paragraphs[0].font.color.rgb = RGBColor(255, 0, 0)
elif font_colors == "green":
slide.shapes.title.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 255, 0)
slide.placeholders[1].text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 255, 0)
elif font_colors == "blue":
slide.shapes.title.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 0, 255)
slide.placeholders[1].text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 0, 255)
else:
slide.shapes.title.text_frame.paragraphs[0].font.color.rgb = RGBColor(255, 255, 255)
slide.placeholders[1].text_frame.paragraphs[0].font.color.rgb = RGBColor(255, 255, 255)
def create_section_header_slide(title, slide_bg_color, font_colors):
layout = root.slide_layouts[2]
slide = root.slides.add_slide(layout)
background = slide.background
if slide_bg_color == "white":
background.fill.solid()
background.fill.fore_color.rgb = RGBColor(255, 255, 255)
elif slide_bg_color == "black":
background.fill.solid()
background.fill.fore_color.rgb = RGBColor(0, 0, 0)
elif slide_bg_color == "red":
background.fill.solid()
background.fill.fore_color.rgb = RGBColor(255, 0, 0)
elif slide_bg_color == "green":
background.fill.solid()
background.fill.fore_color.rgb = RGBColor(0, 255, 0)
elif slide_bg_color == "blue":
background.fill.solid()
background.fill.fore_color.rgb = RGBColor(0, 0, 255)
else:
# If an invalid color is provided, default to white
background.fill.solid()
background.fill.fore_color.rgb = RGBColor(255, 255, 255)
slide.shapes.title.text = title
if font_colors == "white":
slide.shapes.title.text_frame.paragraphs[0].font.color.rgb = RGBColor(255, 255, 255)
elif font_colors == "black":
slide.shapes.title.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 0, 0)
elif font_colors == "red":
slide.shapes.title.text_frame.paragraphs[0].font.color.rgb = RGBColor(255, 0, 0)
elif font_colors == "green":
slide.shapes.title.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 255, 0)
elif font_colors == "blue":
slide.shapes.title.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 0, 255)
else:
slide.shapes.title.text_frame.paragraphs[0].font.color.rgb = RGBColor(255, 255, 255)
def create_title_and_content_slide(title, content, slide_bg_color,font_colors):
layout = root.slide_layouts[1]
slide = root.slides.add_slide(layout)
background = slide.background
if slide_bg_color == "white":
background.fill.solid()
background.fill.fore_color.rgb = RGBColor(255, 255, 255)
elif slide_bg_color == "black":
background.fill.solid()
background.fill.fore_color.rgb = RGBColor(0, 0, 0)
elif slide_bg_color == "red":
background.fill.solid()
background.fill.fore_color.rgb = RGBColor(255, 0, 0)
elif slide_bg_color == "green":
background.fill.solid()
background.fill.fore_color.rgb = RGBColor(0, 255, 0)
elif slide_bg_color == "blue":
background.fill.solid()
background.fill.fore_color.rgb = RGBColor(0, 0, 255)
else:
# If an invalid color is provided, default to white
background.fill.solid()
background.fill.fore_color.rgb = RGBColor(255, 255, 255)
slide.shapes.title.text = title
# slide.placeholders[1].text = content
content_placeholder = slide.placeholders[1]
content_placeholder.text = content
# set font color of bullet points in content
# for paragraph in content_placeholder.text_frame.paragraphs:
# paragraph.font.color.rgb = RGBColor(255, 255, 255)
if font_colors == "white":
for paragraph in content_placeholder.text_frame.paragraphs:
paragraph.font.color.rgb = RGBColor(255, 255, 255)
slide.shapes.title.text_frame.paragraphs[0].font.color.rgb = RGBColor(255, 255, 255)
elif font_colors == "black":
slide.shapes.title.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 0, 0)
for paragraph in content_placeholder.text_frame.paragraphs:
paragraph.font.color.rgb = RGBColor(0, 0, 0)
elif font_colors == "red":
for paragraph in content_placeholder.text_frame.paragraphs:
paragraph.font.color.rgb = RGBColor(255, 0, 0)
slide.shapes.title.text_frame.paragraphs[0].font.color.rgb = RGBColor(255, 0, 0)
elif font_colors == "green":
for paragraph in content_placeholder.text_frame.paragraphs:
paragraph.font.color.rgb = RGBColor(0, 255, 0)
slide.shapes.title.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 255, 0)
elif font_colors == "blue":
for paragraph in content_placeholder.text_frame.paragraphs:
paragraph.font.color.rgb = RGBColor(0, 0, 255)
slide.shapes.title.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 0, 255)
else:
for paragraph in content_placeholder.text_frame.paragraphs:
paragraph.font.color.rgb = RGBColor(255, 255, 255)
slide.shapes.title.text_frame.paragraphs[0].font.color.rgb = RGBColor(255, 255, 255)
def create_title_and_content_and_image_slide(title, content, image_query, slide_bg_color,font_colors):
layout = root.slide_layouts[8]
slide = root.slides.add_slide(layout)
background = slide.background
if slide_bg_color == "white":
background.fill.solid()
background.fill.fore_color.rgb = RGBColor(255, 255, 255)
elif slide_bg_color == "black":
background.fill.solid()
background.fill.fore_color.rgb = RGBColor(0, 0, 0)
elif slide_bg_color == "red":
background.fill.solid()
background.fill.fore_color.rgb = RGBColor(255, 0, 0)
elif slide_bg_color == "green":
background.fill.solid()
background.fill.fore_color.rgb = RGBColor(0, 255, 0)
elif slide_bg_color == "blue":
background.fill.solid()
background.fill.fore_color.rgb = RGBColor(0, 0, 255)
else:
# If an invalid color is provided, default to white
background.fill.solid()
background.fill.fore_color.rgb = RGBColor(255, 255, 255)
slide.shapes.title.text = title
# slide.placeholders[2].text = content
content_placeholder = slide.placeholders[2]
content_placeholder.text = content
if font_colors == "white":
for paragraph in content_placeholder.text_frame.paragraphs:
paragraph.font.color.rgb = RGBColor(255, 255, 255)
slide.shapes.title.text_frame.paragraphs[0].font.color.rgb = RGBColor(255, 255, 255)
elif font_colors == "black":
for paragraph in content_placeholder.text_frame.paragraphs:
paragraph.font.color.rgb = RGBColor(0, 0, 0)
slide.shapes.title.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 0, 0)
elif font_colors == "red":
for paragraph in content_placeholder.text_frame.paragraphs:
paragraph.font.color.rgb = RGBColor(255, 0, 0)
slide.shapes.title.text_frame.paragraphs[0].font.color.rgb = RGBColor(255, 0, 0)
elif font_colors == "green":
for paragraph in content_placeholder.text_frame.paragraphs:
paragraph.font.color.rgb = RGBColor(0, 255, 0)
slide.shapes.title.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 255, 0)
elif font_colors == "blue":
for paragraph in content_placeholder.text_frame.paragraphs:
paragraph.font.color.rgb = RGBColor(0, 0, 255)
slide.shapes.title.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 0, 255)
else:
for paragraph in content_placeholder.text_frame.paragraphs:
paragraph.font.color.rgb = RGBColor(255, 255, 255)
slide.shapes.title.text_frame.paragraphs[0].font.color.rgb = RGBColor(255, 255, 255)
refresh_bad_coding_practice()
google_crawler = PrefixNameDownloader(image_query)
# google_crawler.crawl(keyword=image_query, max_num=1)
dir_path = os.path.dirname(os.path.realpath(google_crawler))
file_name = glob.glob(f"prefix_{bad_coding_practice}*")
# print(file_name)
img_path = os.path.join(dir_path, file_name[0])
slide.shapes.add_picture(img_path, slide.placeholders[1].left, slide.placeholders[1].top,
slide.placeholders[1].width, slide.placeholders[1].height)
def find_text_in_between_tags(text, start_tag, end_tag):
start_pos = text.find(start_tag)
end_pos = text.find(end_tag)
result = []
while start_pos > -1 and end_pos > -1:
text_between_tags = text[start_pos+len(start_tag):end_pos]
result.append(text_between_tags)
start_pos = text.find(start_tag, end_pos+len(end_tag))
end_pos = text.find(end_tag, start_pos)
res1 = "".join(result)
res2 = re.sub(r"\[IMAGE\].*?\[/IMAGE\]", '', res1)
if len(result) > 0:
return res2
else:
return ""
def search_for_slide_type(text):
tags = ["[L_TS]", "[L_CS]", "[L_IS]", "[L_THS]"]
found_text = next((s for s in tags if s in text), None)
return found_text
def parse_response(reply,color,font_colors):
slide_bg_color = color.lower()
list_of_slides = reply.split("[SLIDEBREAK]")
for slide in list_of_slides:
slide_type = search_for_slide_type(slide)
if slide_type == "[L_TS]":
create_title_slide(find_text_in_between_tags(str(slide), "[TITLE]", "[/TITLE]"),
find_text_in_between_tags(str(slide), "[SUBTITLE]", "[/SUBTITLE]"),slide_bg_color,font_colors)
elif slide_type == "[L_CS]":
create_title_and_content_slide("".join(find_text_in_between_tags(str(slide), "[TITLE]", "[/TITLE]")),
"".join(find_text_in_between_tags(str(slide), "[CONTENT]",
"[/CONTENT]")),slide_bg_color,font_colors)
elif slide_type == "[L_IS]":
create_title_and_content_and_image_slide("".join(find_text_in_between_tags(str(slide), "[TITLE]",
"[/TITLE]")),
"".join(find_text_in_between_tags(str(slide), "[CONTENT]",
"[/CONTENT]")),
"".join(find_text_in_between_tags(str(slide), "[IMAGE]",
"[/IMAGE]")),slide_bg_color,font_colors)
elif slide_type == "[L_THS]":
create_section_header_slide("".join(find_text_in_between_tags(str(slide), "[TITLE]", "[/TITLE]")),slide_bg_color,font_colors)
def find_title():
# res = ''.join(random.choices(string.ascii_uppercase + string.digits, k=7))
# val = str(res)
# return val
return root.slides[0].shapes.title.text
delete_all_slides()
# print(response)
parse_response(response['choices'][0]['message']['content'],color,font_colors)
path_new = "files"
root.save(f"{path_new}/{find_title()}.pptx")
binary_output = BytesIO()
root.save(binary_output)
# print("done")
# return rf"Done! {find_title()} is ready! You can find it at {os.getcwd()}\{find_title()}.pptx"
return f"{path_new}/{find_title()}.pptx",binary_output
# End of PPT Methods
# GTTS
def text_to_speech(text,ext):
tts = gTTS(text, lang='en', tld='co.uk', slow=False)
try:
my_file_name = text[0:20]
except:
my_file_name = "audio"
tts.save(f"temp/{my_file_name}.mp3")
# print(my_file_name)
return my_file_name
now_date = datetime.now()
# round to nearest 15 minutes
now_date = now_date.replace(minute=now_date.minute // 15 * 15, second=0, microsecond=0)
# split into date and time objects
now_time = now_date.time()
now_date = now_date.date() + timedelta(days=1)
# List of methods
def generateBlogTopics(prompt1):
response = openai.Completion.create(
engine="text-davinci-003",
# engine="gpt-3.5-turbo",
prompt="Generate blog topics on: {}. \n \n 1. ".format(prompt1),
temperature=0.7,
max_tokens=100,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
return response['choices'][0]['text']
def generateBlogSections(prompt1):
response = openai.Completion.create(
engine="text-davinci-003",
# engine="gpt-3.5-turbo",
prompt="Expand the blog title in to high level blog sections: {} \n\n- Introduction: ".format(prompt1),
temperature=0.6,
max_tokens=100,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
return response['choices'][0]['text']
def blogSectionExpander(prompt1):
response = openai.Completion.create(
engine="text-davinci-003",
# engine="gpt-3.5-turbo",
prompt="Expand the blog section in to a detailed professional , witty and clever explanation.\n\n {}".format(prompt1),
temperature=0.7,
max_tokens=750,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
return response['choices'][0]['text']
def generate_legal_content(user_input):
try:
completion = openai.ChatCompletion.create(model="gpt-4o", messages=[
{"role": "system", "content": "You are alphaGPT, an AI assistant custom trained and created by Alpha AI to work within the legal industry of India. You are proficient at everytask when it comes to law, legal processes, legal resources etc."},
{"role": "user", "content": prompt}
],max_tokens=3000, temperature = 0.7,presence_penalty = 0.1,frequency_penalty = 0.1)
# print(type(completion))
result = completion.choices[0].message.content
return result
except openai.error.APIError as e:
#Handle API error here, e.g. retry or log
print(f"OpenAI API returned an API Error: {e}")
pass
except openai.error.APIConnectionError as e:
#Handle connection error here
print(f"Failed to connect to OpenAI API: {e}")
pass
except openai.error.RateLimitError as e:
#Handle rate limit error (we recommend using exponential backoff)
print(f"OpenAI API request exceeded rate limit: {e}")
pass
def load_lottiefile(filepath: str):
with open(filepath, "r") as f:
return json.load(f)
im = Image.open("favicon.ico")
st.set_page_config(
page_title="Generative AI Toolkit",
page_icon=im,
layout="centered",
initial_sidebar_state="expanded",
)
# Define the metadata
image_url = "aai_edu.png"
hide_st_style = """
<head>
<!-- Primary Meta Tags -->
<title>Alpha AI - Among India's leading AI Research and Development Startups</title>
<meta name="title" content="Alpha AI - Among India's leading AI Research and Development Startups">
<meta name="description" content="Empowering businesses with transformative AI solutions through customer-centricity, strategic expertise, and relentless innovation.">
<!-- Open Graph / Facebook -->
<meta property="og:type" content="website">
<meta property="og:url" content="https://alphaai.streamlit.app/">
<meta property="og:title" content="Alpha AI - Among India's leading AI Research and Development Startups">
<meta property="og:description" content="Empowering businesses with transformative AI solutions through customer-centricity, strategic expertise, and relentless innovation.">
<meta property="og:image" content="{image_url}">
<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:url" content="https://alphaai.streamlit.app/">
<meta property="twitter:title" content="Alpha AI - Among India's leading AI Research and Development Startups">
<meta property="twitter:description" content="Empowering businesses with transformative AI solutions through customer-centricity, strategic expertise, and relentless innovation.">
<meta property="twitter:image" content="{image_url}">
</head>
<style>
#MainMenu {visibility: hidden;}
footer {visibility: hidden;}
header {visibility: hidden;}
html, body, [class*="css"] {
font-family: Montserrat;
font-weight: 350;
}
</style>
"""
st.markdown(hide_st_style, unsafe_allow_html=True)
def load_lottiefile(filepath: str):
with open(filepath, "r") as f:
return json.load(f)
def load_lottieurl(url: str):
r = requests.get(url)
if r.status_code != 200:
return None
return r.json()
# lottie_coding = load_lottiefile("comp_anim.json") # replace link to local lottie file
lottie_hello1 = load_lottieurl("https://assets6.lottiefiles.com/packages/lf20_AHptq1.json")
# lottie_hello1 = load_lottieurl("https://assets5.lottiefiles.com/packages/lf20_hlvOdjjxTF.json")
place1 = st.empty()
with place1.container():
anima1 , anima2 = st.columns([2,1])
with anima1:
# st.image("aai_black.png", width = 350, use_column_width=True)
st.image("aai_white.png", width = 350, use_column_width=True)
with anima2:
st_lottie(
lottie_hello1,
speed=1,
reverse=False,
loop=True,
quality="high", # medium ; high
height=220,
width=220,
key=None,
)
__login__obj = __login__(auth_token = "courier_auth_token",
company_name = "Alpha AI",
width = 200, height = 250,
logout_button_name = 'Logout', hide_menu_bool = False,
hide_footer_bool = True) #,
# lottie_url = 'https://assets2.lottiefiles.com/packages/lf20_jcikwtux.json')
LOGGED_IN = __login__obj.build_login_ui()
if 'openai.api_key' not in st.session_state:
st.session_state['openai.api_key'] = openai.api_key
place2 = st.empty()
with place1.container():
st.header('Welcome to our Generative AI Toolkit :sunglasses:')
st.subheader("The results of our toolkit are backed by a large-scale unsupervised language model that can generate paragraphs of text. This transformer-based language model is based on the GPT-3 model architecture initially proposed by OpenAI, intakes a sentence or partial sentence and predicts subsequent text from that input.")
st.subheader("There is a current limit of a few tokens on various aspects of the tool that implies that you can create content containing upto 750 words")
st.caption('For any feedback or to get personalization done for your usecases, contact us on alphaaiofficial@gmail.com :sunglasses:')
st.info("ChatGPT, GPT3 Models, Langchain have been integrated with the latest update...")
# with open('creds.yaml') as file:
# config = yaml.load(file, Loader=SafeLoader)
# # load hashed passwords
# file_path = Path(__file__).parent / "hashed_pw.pkl"
# with file_path.open("rb") as file:
# hashed_passwords = pickle.load(file)
# with st.container():
# tab1, tab2, tab3, tab4 = st.tabs(["Login", "Reset", "Register","Forgot Password"])
# with tab1:
# authenticator = stauth.Authenticate(
# config['credentials'],
# config['cookie']['name'],
# config['cookie']['key'],
# config['cookie']['expiry_days'],
# config['preauthorized']
# )
# name, authentication_status, username = authenticator.login("Login", "main")
# with tab2:
# try:
# if authenticator.reset_password(username, 'Reset password'):
# st.success('Password modified successfully')
# with open('creds.yaml', 'w') as file:
# yaml.dump(config, file, default_flow_style=False)
# except Exception as e:
# st.error(e)
# with tab3:
# try:
# if authenticator.register_user('Register user', preauthorization=False):
# st.success('User registered successfully')
# with open('creds.yaml', 'w') as file:
# yaml.dump(config, file, default_flow_style=False)
# except Exception as e:
# st.error(e)
# with tab4:
# try:
# username_forgot_pw, email_forgot_password, random_password = authenticator.forgot_password('Forgot password')
# if username_forgot_pw:
# st.success('New password sent securely')
# # Random password to be transferred to user securely
# with open('creds.yaml', 'w') as file:
# yaml.dump(config, file, default_flow_style=False)
# else:
# st.error('Username not found')
# except Exception as e:
# st.error(e)
# if authentication_status == False:
# st.error("Username/password is incorrect")
# if authentication_status == None:
# st.info("Please enter your username and password")
# if authentication_status:
if st.session_state['LOGGED_IN'] == True:
place1.empty()
place2.empty()
# horizontal menu
with st.sidebar:
# st.write(f"Hello user!")
# Store and display user's OpenAI API key
api_key = st.text_input("Enter your OpenAI API key:", value = st.session_state['openai.api_key'], type="password", key='openai_session_key')
openai.api_key = api_key
st.session_state["openai.api_key"] = api_key
st.write(f"Your OpenAI API key is: {api_key}")
selected = option_menu(
menu_title="Generative AI Toolkit", # required
options=[
"Home",
"---",
"Chat Mode",
"---" ,
"alphaGPT",
"---" ,
"Act-Prompts",
"---" ,
"Food Blogger",
"---" ,
"Travel Blogger",
"---" ,
"E-Commerce",
"---" ,
"Business Brief Generator",
"---" ,
"Keyword Extraction",
"---" ,
"Summarization",
"---" ,
"Grammar Correction",
"---" ,
"Restaurant Reviews",
"---" ,
"Image Generator",
"---" ,
"Blog Generator",
"---" ,
"Content Paraphraser",
"---" ,
"Story Teller",
"---" ,
"Social Media Copywriting",
"---" ,
"Marketing Campaign",
"---" ,
"PPT Generator",
"---" ,
"AD Generator",
"---" ,
"Legal Aid",
"---" ,
"Travel and Tourism",
"---",
"Document Chat"
# ,
# "---",
# "GPT-LipSync"
],# required
icons=[
"house-fill",
"---",
"robot",
"---" ,
"bi bi-chat-left-dots-fill",
"---" ,
"person-video",
"---" ,
"cup-straw",
"---" ,
"compass",
"---" ,
"badge-ad",
"---" ,
"file-earmark-richtext",
"---" ,
"card-text",
"---" ,
"justify",
"---" ,
"fonts",
"---" ,
"stars",
"---" ,
"images",
"---" ,
"bi bi-envelope",
"---" ,
"cursor-text",
"---" ,
"card-text",
"---" ,
"telegram",
"---" ,
"people",
"---" ,
"file-slides-fill",
"---" ,
"pencil-square",
"---" ,
"book",
"---" ,
"geo-alt-fill",
"---",
"file-pdf-fill"
# ,
# "---",
# "stop-circle"
], # optional
menu_icon="cast", # optional
default_index=0, # optional
orientation="vertical",
)
if selected == "Home":
st.header('Welcome to our Generative AI Toolkit :sunglasses:')
st.subheader("The results of our toolkit are backed by a large-scale unsupervised language model that can generate paragraphs of text. This transformer-based language model is based on the GPT-3 model architecture initially proposed by OpenAI, intakes a sentence or partial sentence and predicts subsequent text from that input.")
st.subheader("There is a current limit of a few tokens on various aspects of the tool that implies that you can create content containing upto 750 words")
st.caption('For any feedback or to get personalization done for your usecases, contact us on alphaaiofficial@gmail.com :sunglasses:')
st.info("ChatGPT, GPT3 Models, Langchain have been integrated with the latest update...")
#For Chat GPT
elif selected == "Chat Mode":
# Initialize model selection and session state
model = st.selectbox(
"Select a model",
("gpt-4o", "gpt-3.5-turbo", "gpt-3.5-turbo-0301")
)
# client = OpenAI(openai_api_key=api_key)
if "openai_model" not in st.session_state:
st.session_state["openai_model"] = model
if "messages" not in st.session_state:
st.session_state.messages = []
# Display existing chat messages
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
# User input and assistant response handling
if prompt := st.chat_input("What is up?"):
st.session_state.messages.append({"role": "user", "content": prompt})
with st.chat_message("user"):
st.markdown(prompt)
# Call OpenAI API to generate response
response = openai.ChatCompletion.create(
model=st.session_state["openai_model"],
messages=[
{"role": m["role"], "content": m["content"]}
for m in st.session_state.messages
],
)
# Extract and display assistant's response
assistant_response = response['choices'][0]['message']['content']
st.session_state.messages.append({"role": "assistant", "content": assistant_response})
with st.chat_message("assistant"):
st.markdown(assistant_response)
# Clear session state
st.info("Click on 'Clear' (at times, twice) to clear data!")
if st.button("Clear", type="primary", use_container_width=True):
st.session_state.clear()
#For Chat GPT
elif selected == "alphaGPT":
st.subheader("alphaGPT: An AI-powered chatbot")
# You can also use radio buttons instead
selected_alpha = st.radio("Stream the result in realtime or view it in one go!",("NO Streaming","Streaming"))
# selected = pills("", ["NO Streaming", "Streaming"], ["π", "π‘"])
user_input = st.text_area("You: ",placeholder = "Ask me anything ...", key="input", height=300)
if st.button("Submit", type="primary"):
st.markdown("----")
res_box = st.empty()
if selected_alpha == "Streaming":
report = []
temp_var = ""
# Looping over the response
model_v3 = "gpt-4o"
# model_v4 = "gpt-4-0314"
try:
for resp in openai.ChatCompletion.create(model=model_v3,
messages=[
{"role": "system", "content": "You are an AI language model custom trained and created by Alpha AI. You are proficient at everytask."},
{"role": "user", "content": user_input}
],
max_tokens=2500,
temperature = 0.6,
presence_penalty = 0.1,
frequency_penalty = 0.1,
stream = True):
# join method to concatenate the elements of the list
# into a single string,
# then strip out any empty strings
# print(resp)
if "content" in resp["choices"][0]["delta"]:
report.append(resp["choices"][0]["delta"]["content"])
# report.append(resp.choices[0].delta.content)
result = "".join(report).strip()
# result = result.replace("\n", "")
res_box.markdown(f'{result}')
temp_var = f'{result}'
else:
pass
# print(temp_var)
# For TTS
st.markdown(f"Wait for your audio to render")
ext = dt = datetime.now()
result_aud = text_to_speech(temp_var, ext)
audio_file = open(f"temp/{result_aud}.mp3", "rb")
audio_bytes = audio_file.read()
st.markdown(f"Your audio:")
st.audio(audio_bytes, format="audio/mp3", start_time=0)
except openai.error.APIError as e:
#Handle API error here, e.g. retry or log
print(f"OpenAI API returned an API Error: {e}")
pass
except openai.error.APIConnectionError as e:
#Handle connection error here
print(f"Failed to connect to OpenAI API: {e}")
pass
except openai.error.RateLimitError as e:
#Handle rate limit error (we recommend using exponential backoff)
print(f"OpenAI API request exceeded rate limit: {e}")
pass
else:
try:
completion = openai.ChatCompletion.create(model="gpt-4o", messages=[
{"role": "system", "content": "You are an AI assistant custom trained and created by Alpha AI. You are proficient at everytask."},
{"role": "user", "content": user_input}
],max_tokens=2500, temperature = 0.6,presence_penalty = 0.1,frequency_penalty = 0.1)
# print(type(completion))
result = completion.choices[0].message.content
res_box.write(result)
# For TTS
st.markdown(f"Wait for your audio to render")
ext = dt = datetime.now()
result_aud = text_to_speech(result,ext)
audio_file = open(f"temp/{result_aud}.mp3", "rb")
audio_bytes = audio_file.read()
st.markdown(f"Your audio:")
st.audio(audio_bytes, format="audio/mp3", start_time=0)
except openai.error.APIError as e:
#Handle API error here, e.g. retry or log
print(f"OpenAI API returned an API Error: {e}")
pass
except openai.error.APIConnectionError as e:
#Handle connection error here
print(f"Failed to connect to OpenAI API: {e}")
pass
except openai.error.RateLimitError as e:
#Handle rate limit error (we recommend using exponential backoff)
print(f"OpenAI API request exceeded rate limit: {e}")
pass
# pyttsx3.speak(result)
st.markdown("----")
st.warning("Below are some examples one can refer to. To use simply copy paste it and edit the content.")
st.info("""Write a product page for my company called HealthyBites that provides healthy organic meal delivery.
The goal is to persuade potential customers to choose HealthyBites as their partner in achieving better health and wellness
The target audience is health-conscious individuals who want to improve their eating habits but struggle with limited time or cooking skills.
Ensure the text is an ideal length based on the industry standard.
Write using the English language in a fun style and creative writing tone.
Use a first-person narrative.
Format the text in a table with the 5 rows: [hero section β add persuasive power words], [description β include emotional appeal], [benefits β use benefit-focused language], [FAQs β include relevant facts and data] and [call to action β express urgency].""")
st.info("""
Write a blog post that explains the difficulties and challenges implementing SEO.
The goal is to explain the challenges and provide some simple tips and guidelines to overcome these challenges.
The target audience is marketers and business owners.
Ensure the text is an ideal length based on the industry standard.
Write using the British language in a informal style and excitied writing tone.
Use a first-person narrative.
Provide a compelling and catchy title in H1 format.
Format the text as follows using HTML code and H2 sub headings: [introduction β add persuasive power words], [main body β include emotional appeal and break out into sub-sections] and [conclusion β express urgency and include a CTA].
""")
st.info("""
Generate a table summarising the keywords used in the above blog. Include 4 columns [keyword], [intent], [keyword density] and [user β include typical job titles that may be interested in the keywords]. Order by frequency use.
""")
st.info("""
Generate a table summarising keywords that are likely to be popular with people searching Google specifically for information on [topic/ideas]. Include 3 columns [keyword], [intent] and [user β typical job titles that may be interested]. Order relevancy to the topic.
""")
st.info("""
Write a blog post that [provide the title, topic or detail about whatβs needed].
The goal is [explain the desired outcome].
The target audience is [state the audience].
Ensure the text is an ideal length based on the industry standard.
Write using the [state your country] language in a [include the style β see examples below] style and [nclude the tone β see examples below] writing tone.
Use a [first-person/third-person] narrative.
Optimise the text for the following keywords [insert researched keywords] in an SEO friendly manner.
Provide a compelling and catchy title in H1 format.
Format the text as follows using HTML code and H2 sub headings: [introduction β add persuasive power words], [main body β include emotional appeal and break out into sub-sections] and [conclusion β express urgency and include a CTA].
""")
st.info("""
Write a short explanation of [topic] in the [country] language that includes specific bullet points relevant to a [country] audience
""")
st.info("""
I want you to act as a [state role]. You will come up with [explain whatβs expected and the audience]. Your words should have [provide additional context and detail, including style and tone]. My first request is [state the topic/request].
""")
elif selected == "Act-Prompts":
st.subheader("Acts & Prompts: Edit prompts and generate content based on acts dynamically.")
act_options = df['act'].unique().tolist()
selected_act = st.selectbox("Select an act", act_options)
# Get corresponding prompt for selected 'act'
prompt = df.loc[df['act'] == selected_act, 'prompt'].values[0]
# Display prompt
st.write("Prompt:")
# Allow user to choose and edit prompt
edited_prompt = st.text_area("Edit prompt", prompt,height=350)
# Generate response using GPT-3.5 API on submit button click
if st.button("Submit", type="primary"):
res_box = st.empty()
report = []
temp_var = ""
# Looping over the response
model_v3 = "gpt-4o"
# model_v4 = "gpt-4-0314"
try:
for resp in openai.ChatCompletion.create(model=model_v3,
messages=[
{"role": "system", "content": "You are an AI language model custom trained and created by Alpha AI. You are proficient at everytask."},
{"role": "user", "content": edited_prompt}
],
max_tokens=2500,
temperature = 0.6,
presence_penalty = 0.1,
frequency_penalty = 0.1,
stream = True):
# join method to concatenate the elements of the list
# into a single string,
# then strip out any empty strings
# print(resp)
if "content" in resp["choices"][0]["delta"]:
report.append(resp["choices"][0]["delta"]["content"])
# report.append(resp.choices[0].delta.content)
result = "".join(report).strip()
# result = result.replace("\n", "")
res_box.markdown(f'{result}')
temp_var = f'{result}'
else:
pass
# print(temp_var)
# For TTS
# st.markdown(f"Wait for your audio to render")
# ext = dt = datetime.now()
# result_aud = text_to_speech(temp_var, ext)
# audio_file = open(f"temp/{result_aud}.mp3", "rb")
# audio_bytes = audio_file.read()
# st.markdown(f"Your audio:")
# st.audio(audio_bytes, format="audio/mp3", start_time=0)
# st.markdown("----")
except openai.error.APIError as e:
#Handle API error here, e.g. retry or log
print(f"OpenAI API returned an API Error: {e}")
pass
except openai.error.APIConnectionError as e:
#Handle connection error here
print(f"Failed to connect to OpenAI API: {e}")
pass
except openai.error.RateLimitError as e:
#Handle rate limit error (we recommend using exponential backoff)
print(f"OpenAI API request exceeded rate limit: {e}")
pass
elif selected == "Food Blogger":
st.subheader("AI powered 'Food Blogger'")
# You can also use radio buttons instead
selected_food = st.radio("Stream the result in realtime or view it in one go!",("NO Streaming","Streaming"))
# selected = pills("", ["NO Streaming", "Streaming"], ["π", "π‘"])
user_input = st.text_input("You: ",placeholder = "Ask me anything ...", key="input")
if st.button("Submit", type="primary"):
st.markdown("----")
res_box = st.empty()
content_sys = "Act as an amazing food blogger who works with Tripsero and like to talk only about food, restaurants, cafe, meals and all about food and drinks"
if selected_food == "Streaming":
report = []
temp_var2 = ""
# Looping over the response
try:
for resp in openai.ChatCompletion.create(model="gpt-4o",
messages=[
{"role": "system", "content":content_sys},
{"role": "user", "content": user_input}
],
max_tokens=2500,
temperature = 0.6,
presence_penalty = 0.1,
frequency_penalty = 0.1,
stream = True):
# join method to concatenate the elements of the list
# into a single string,
# then strip out any empty strings
# print(resp)
if "content" in resp["choices"][0]["delta"]:
report.append(resp["choices"][0]["delta"]["content"])
# report.append(resp.choices[0].delta.content)
result = "".join(report).strip()
# result = result.replace("\n", "")
res_box.markdown(f'{result}')
temp_var2 = f'{result}'
else:
pass
# For TTS
st.markdown(f"Wait for your audio to render")
ext = dt = datetime.now()
result_aud2 = text_to_speech(temp_var2,ext)
audio_file = open(f"temp/{result_aud2}.mp3", "rb")
audio_bytes = audio_file.read()
st.markdown(f"Your audio:")
st.audio(audio_bytes, format="audio/mp3", start_time=0)
except openai.error.APIError as e:
#Handle API error here, e.g. retry or log
print(f"OpenAI API returned an API Error: {e}")
pass
except openai.error.APIConnectionError as e:
#Handle connection error here
print(f"Failed to connect to OpenAI API: {e}")
pass
except openai.error.RateLimitError as e:
#Handle rate limit error (we recommend using exponential backoff)
print(f"OpenAI API request exceeded rate limit: {e}")
pass
else:
try:
completion = openai.ChatCompletion.create(model="gpt-4o", messages=[
{"role": "system", "content":content_sys},
{"role": "user", "content": user_input}
],max_tokens=2500, temperature = 0.6,presence_penalty = 0.1,frequency_penalty = 0.1)
# print(type(completion))
result = completion.choices[0].message.content
res_box.write(result)
# For TTS
st.markdown(f"Wait for your audio to render")
ext = dt = datetime.now()
result_aud2 = text_to_speech(result,ext)
audio_file = open(f"temp/{result_aud2}.mp3", "rb")
audio_bytes = audio_file.read()
st.markdown(f"Your audio:")
st.audio(audio_bytes, format="audio/mp3", start_time=0)
# pyttsx3.speak(result)
except openai.error.APIError as e:
#Handle API error here, e.g. retry or log
print(f"OpenAI API returned an API Error: {e}")
pass
except openai.error.APIConnectionError as e:
#Handle connection error here
print(f"Failed to connect to OpenAI API: {e}")
pass
except openai.error.RateLimitError as e:
#Handle rate limit error (we recommend using exponential backoff)
print(f"OpenAI API request exceeded rate limit: {e}")
pass
st.markdown("----")
elif selected == "Travel Blogger":
st.subheader("AI powered 'Travel Blogger'")
# You can also use radio buttons instead
selected_travel = st.radio("Stream the result in realtime or view it in one go!",("NO Streaming","Streaming"))
# selected = pills("", ["NO Streaming", "Streaming"], ["π", "π‘"])
user_input = st.text_input("You: ",placeholder = "Ask me anything ...", key="input")
if st.button("Submit", type="primary"):
st.markdown("----")
res_box = st.empty()
content_sys = "Act as a famous Indian travel blogger who loves who works with Tripsero and travels to different places, writes about his personal experiences and more. You love adventures, random trips, personalized experience based travel and in general love the travel, tourism and hospitality industry."
if selected_travel == "Streaming":
report = []
temp_var3 = ""
# Looping over the response
try:
for resp in openai.ChatCompletion.create(model="gpt-4o",
messages=[
{"role": "system", "content":content_sys},
{"role": "user", "content": user_input}
],
max_tokens=2500,
temperature = 0.6,
presence_penalty = 0.1,
frequency_penalty = 0.1,
stream = True):
# join method to concatenate the elements of the list
# into a single string,
# then strip out any empty strings
# print(resp)
if "content" in resp["choices"][0]["delta"]:
report.append(resp["choices"][0]["delta"]["content"])
# report.append(resp.choices[0].delta.content)
result = "".join(report).strip()
# result = result.replace("\n", "")
res_box.markdown(f'{result}')
temp_var3 = f'{result}'
else:
pass
# For TTS
st.markdown(f"Wait for your audio to render")
ext = dt = datetime.now()
result_aud3 = text_to_speech(temp_var3,ext)
audio_file = open(f"temp/{result_aud3}.mp3", "rb")
audio_bytes = audio_file.read()
st.markdown(f"Your audio:")
st.audio(audio_bytes, format="audio/mp3", start_time=0)
except openai.error.APIError as e:
#Handle API error here, e.g. retry or log
print(f"OpenAI API returned an API Error: {e}")
pass
except openai.error.APIConnectionError as e:
#Handle connection error here
print(f"Failed to connect to OpenAI API: {e}")
pass
except openai.error.RateLimitError as e:
#Handle rate limit error (we recommend using exponential backoff)
print(f"OpenAI API request exceeded rate limit: {e}")
pass
else:
try:
completion = openai.ChatCompletion.create(model="gpt-4o", messages=[
{"role": "system", "content":content_sys},
{"role": "user", "content": user_input}
],max_tokens=2500, temperature = 0.6,presence_penalty = 0.1,frequency_penalty = 0.1)
# print(type(completion))
result = completion.choices[0].message.content
res_box.write(result)
# For TTS
st.markdown(f"Wait for your audio to render")
ext = dt = datetime.now()
result_aud3 = text_to_speech(result,ext)
audio_file = open(f"temp/{result_aud3}.mp3", "rb")
audio_bytes = audio_file.read()
st.markdown(f"Your audio:")
st.audio(audio_bytes, format="audio/mp3", start_time=0)
# pyttsx3.speak(result)
except openai.error.APIError as e:
#Handle API error here, e.g. retry or log
print(f"OpenAI API returned an API Error: {e}")
pass
except openai.error.APIConnectionError as e:
#Handle connection error here
print(f"Failed to connect to OpenAI API: {e}")
pass
except openai.error.RateLimitError as e:
#Handle rate limit error (we recommend using exponential backoff)
print(f"OpenAI API request exceeded rate limit: {e}")
pass
st.markdown("----")
# For E-Commerce
elif selected == "E-Commerce":
st.subheader('Generate content for various e-Commerce scenarios.')
option = st.selectbox('What would you like to do today??',
(
'Product Collection Description',
'Product Title Generator',
'Collection Title Generator',
'Product Descriptions',
'Ad-caption Generator',
'Ad-copy Generator',
'Article Generator',
'Social media page description',
'Email Content - Outreach',
'Homepage Content',
''
'Homepage Headline'
))
if option =="Product Collection Description":
product = st.text_input("What type of product is it?")
brand = st.text_input("Enter the brand name.")
final_pmt = "Act as an ecommerce merchandising expert and create a product collection description for the " + product + " from the brand " + brand
elif option =="Product Title Generator":
product = st.text_input("What type of product is it?")
brand = st.text_input("Enter the brand name.")
industry = st.text_input("Enter the industry of the brand.")
final_pmt = "Behave like an ecommerce merchandising specialist and draft a product title for " + product + " from " + brand + ", a " + industry + " brand."
elif option =="Collection Title Generator":
product = st.text_input("What type of product is it?")
brand = st.text_input("Enter the brand name.")
final_pmt = "Act as an ecommerce merchandising expert and create a product collection title for " + product + " from " + brand + "."
elif option =="Product Descriptions":
product = st.text_input("What type of product is it?")
brand = st.text_input("Enter the brand name.")
ideal_customer_persona = st.text_input("Enter the ideal customer persona.")
final_pmt = "Think like an ecommerce merchandising specialist and write a product description to list " +product+ " on an ecommerce store " + brand + " for a customer who is a "+ ideal_customer_persona
elif option =="Ad-caption Generator":
product = st.text_input("What type of product is it?")
brand = st.text_input("Enter the brand name.")
channel = st.selectbox('Choose the social media channel.',
(
'Instagram',
'Facebook',
'LinkedIn',
'Twitter',
))
final_pmt = "Think like an ecommerce digital advertiser and create an ad caption for the product "+ product+ " from the brand " + brand + ". Optimize the caption for " + channel + " ads and relevant character limits."
elif option =="Ad-copy Generator":
product = st.text_input("What type of product is it?")
brand = st.text_input("Enter the brand name.")
channel = st.selectbox('Choose the social media channel.',
(
'Instagram',
'Facebook',
'LinkedIn',
'Twitter',
))
final_pmt = "Think like an ecommerce digital advertising copywriter and create ad copy for the product " + product + " from the brand '"+brand+"'. Optimize the copy for "+channel+" ads."
elif option =="Article Generator":
product = st.text_input("What type of product is it?")
brand = st.text_input("Enter the brand name.")
final_pmt = "Act as an ecommerce content writer and write an article on the product '"+product+"' from the brand '"+brand+"'"
elif option =="Social media page description":
product = st.text_input("What type of product is it?")
brand = st.text_input("Enter the brand name.")
channel = st.selectbox('Choose the social media channel.',
(
'Instagram',
'Facebook',
'LinkedIn',
'Twitter',
))
industry = st.text_input("Enter the industry of the brand.")
final_pmt = "Think like an ecommerce social media specialist and write a 90 character "+channel+" page description for a "+industry+" brand named "+brand+" which sells "+product
elif option =="Email Content - Outreach":
product = st.text_input("What type of product is it?")
brand = st.text_input("Enter the brand name.")
ideal_customer_persona = st.text_input("Enter the ideal customer persona.")
industry = st.text_input("Enter the industry of the brand.")
final_pmt = "Act like an email marketing expert for ecommerce and draft an email campaign for the product '"+product+"' from the brand '"+brand+"', belonging to the "+industry+" industry. The campaign is intended for a "+ideal_customer_persona+"."
elif option =="Homepage Content":
# product = st.text_input("What type of product is it?")
brand = st.text_input("Enter the brand name.")
industry = st.text_input("Enter the industry of the brand.")
final_pmt = "Act like an ecommerce content writer and create homepage content for a "+industry+" product by the brand '"+brand+"'"
elif option =="Homepage Headline":
product = st.text_input("What type of product is it, what is it called?")
brand = st.text_input("Enter the brand name.")
industry = st.text_input("Enter the industry of the brand.")
final_pmt = "Behave like an ecommerce expert and create a homepage headline for a "+industry+" product called "+product+" from the brand "+brand
else:
st.text("Please select an option!")
if st.button("Submit", type="primary"):
res_box6 = st.empty()
report6 = []
# Looping over the response
try:
for resp in openai.ChatCompletion.create(model="gpt-4o",
messages=[
{
"role": "system", "content": "Act As An AI Advertiser custom trained and created by Alpha AI. You are proficient at everytask.",
"role": "user", "content": final_pmt
}
],
max_tokens=4000,
temperature = 0.7,
presence_penalty = 0.1,
frequency_penalty = 0.1,
stream = True):
if "content" in resp["choices"][0]["delta"]:
report6.append(resp["choices"][0]["delta"]["content"])
# report.append(resp.choices[0].delta.content)
result = "".join(report6).strip()
# result = result.replace("\n", "")
res_box6.markdown(f'{result}')
else:
pass
except openai.error.APIError as e:
#Handle API error here, e.g. retry or log
print(f"OpenAI API returned an API Error: {e}")
pass
except openai.error.APIConnectionError as e:
#Handle connection error here
print(f"Failed to connect to OpenAI API: {e}")
pass
except openai.error.RateLimitError as e:
#Handle rate limit error (we recommend using exponential backoff)
print(f"OpenAI API request exceeded rate limit: {e}")
pass
# For Keyword Extraction
elif selected == "Business Brief Generator":
st.subheader("Business Brief Generator.")
business_name = st.text_input("Enter the name of your business.", max_chars=15)
business_type = st.selectbox('What is the type of your business entity?',(
'Private Limited',
'Limited Liability Partnership',
'One Person Company',
'Partnership',
'Sole Proprietorship'
))
country = "India"
product_service = st.text_area("Please describe your product / service.", max_chars = 230)
short_description = st.text_area("Please provide a short description for your business.", max_chars = 300)
years = st.text_input("For how many years or months has your business been active?", value = "Eg. 2 years / 1 year / 1 month / 4 months.", max_chars = 7)
progress = st.text_area("Please tell us a little about your progress so far.", max_chars = 200)
prompt_business = "Generate an elaborate Business Plan for the following business, using the guidelines provided:\nBusiness Name: " + business_name + "\nBusiness Type: "+business_type+"\nCountry: "+country+"\nProduct or Service: "+product_service+"\nShort Business Description: "+short_description+"\nYears in operation: "+years+"\nBusiness progress to date: "+ progress+"\n\nGuidelines: Start the company description by listing the business name and company structure, if one is provided. Write a detailed business description for the short description provided, in a professional business tone. Describe the industry the business will be operating in and re-write the business progress to date. Finally, provide a numbered list of five suitable business objectives and a list of 5 plan of action deliverables for this business. For each objective and plan of action, describe how the it fits the business needs and how it will benefit the stakeholders in the long run."
if st.button("Generate", type="primary"):
res_box_bpg = st.empty()
report_bpg = []
# Looping over the response
try:
for resp in openai.ChatCompletion.create(model="gpt-4o",
messages=[
{
"role": "system", "content": "Act As a business plan maker professional. Very detailed and precise. You are proficient at everytask.",
"role": "user", "content": prompt_business}
],
max_tokens=3500,
temperature = 0.7,
presence_penalty = 0.2,
frequency_penalty = 0.1,
stream = True):
if "content" in resp["choices"][0]["delta"]:
report_bpg.append(resp["choices"][0]["delta"]["content"])
# report.append(resp.choices[0].delta.content)
result = "".join(report_bpg).strip()
# result = result.replace("\n", "")
res_box_bpg.markdown(f'{result}')
else:
pass
except openai.error.APIError as e:
#Handle API error here, e.g. retry or log
print(f"OpenAI API returned an API Error: {e}")
pass
except openai.error.APIConnectionError as e:
#Handle connection error here
print(f"Failed to connect to OpenAI API: {e}")
pass
except openai.error.RateLimitError as e:
#Handle rate limit error (we recommend using exponential backoff)
print(f"OpenAI API request exceeded rate limit: {e}")
pass
# For Keyword Extraction
elif selected == "Keyword Extraction":
st.subheader("Keyword Extraction")
# Create Text Area Widget to enable user to enter texts
article_text = st.text_area("Enter your text corpus & Press Enter, wait for the validation to happen!", max_chars = 500)
# Next, we'll add a check to make sure that the input text is long enough
# to summarize, and display a warning if it is not:
if len(article_text)>10:
if st.button("Extract Keywords",type='primary'):
# Use GPT-3 to generate a summary of the article
try:
response = openai.Completion.create(
engine="text-davinci-003",
# engine="gpt-3.5-turbo",
prompt="Extract keywords from this text: " + article_text,
max_tokens = 60,
temperature = 0.5,
top_p=1.0,
frequency_penalty=0.8,
presence_penalty=0.1
)
# Print the generated summary
res = response["choices"][0]["text"]
st.success(res)
st.download_button('Download result', res)
except openai.error.APIError as e:
#Handle API error here, e.g. retry or log
print(f"OpenAI API returned an API Error: {e}")
pass
except openai.error.APIConnectionError as e:
#Handle connection error here
print(f"Failed to connect to OpenAI API: {e}")
pass
except openai.error.RateLimitError as e:
#Handle rate limit error (we recommend using exponential backoff)
print(f"OpenAI API request exceeded rate limit: {e}")
pass
else:
st.warning("Not enough keywords available!")
# For "Summarization"
elif selected == "Summarization":
st.subheader("Summarization")
# Create Text Area Widget to enable user to enter texts
article_text = st.text_area("Enter your scientific texts to summarize", max_chars = 5000)
# Create Radio Button
output_size = st.radio( label = "What kind of output do you want?",
options= ["To-The-Point", "Concise", "Detailed"]
)
# First, we'll use an if statement to determine the desired output size
# and set the out_token variable accordingly:
if output_size == "To-The-Point":
out_token = 50
elif output_size == "Concise":
out_token = 128
else:
out_token = 516
# Next, we'll add a check to make sure that the input text is long enough
# to summarize, and display a warning if it is not:
if len(article_text)>100:
if st.button("Generate Summary",type='primary'):
# Use GPT-3 to generate a summary of the article
try:
response = openai.Completion.create(
engine="text-curie-001",
prompt="Please summarize this scientific article for me in a few sentences: " + article_text,
max_tokens = out_token,
temperature = 0.5,
)
# Print the generated summary
res = response["choices"][0]["text"]
st.success(res)
# pyttsx3.speak(res)
st.download_button('Download result', res)
# For TTS
st.markdown(f"Wait for your audio to render")
ext = dt = datetime.now()
result_aud4 = text_to_speech(res,ext)
audio_file = open(f"temp/{result_aud4}.mp3", "rb")
audio_bytes = audio_file.read()
st.markdown(f"Your audio:")
st.audio(audio_bytes, format="audio/mp3", start_time=0)
except openai.error.APIError as e:
#Handle API error here, e.g. retry or log
print(f"OpenAI API returned an API Error: {e}")
pass
except openai.error.APIConnectionError as e:
#Handle connection error here
print(f"Failed to connect to OpenAI API: {e}")
pass
except openai.error.RateLimitError as e:
#Handle rate limit error (we recommend using exponential backoff)
print(f"OpenAI API request exceeded rate limit: {e}")
pass
else:
st.warning("Not enough words to summarize!")
# For "Grammar Correction"
elif selected == "Grammar Correction":
st.subheader("Grammar Correction")
# Create Text Area Widget to enable user to enter texts
article_text = st.text_area("Enter the text you would like to correct", max_chars = 1000)
# Create Radio Buttons
output_size = st.radio( label = "What type of correction are you looking for?",
options= ["Standard English", "Sentence Formation"]
)
# First, we'll use an if statement to determine the desired output size
# and set the out_token variable accordingly:
Appending_desc = None
if output_size == "Standard English":
out_token = 600
Appending_desc = "Correct this to standard English: "
elif output_size == "Sentence Formation":
out_token = 600
Appending_desc = "Correct this to standard English sentence: "
# Next, we'll add a check to make sure that the input text is long enough
# to summarize, and display a warning if it is not:
if len(article_text)>1:
if st.button("Correct Grammar",type='primary'):
# Use GPT-3 to generate a summary of the article
try:
response = openai.Completion.create(
engine="text-davinci-003",
prompt= Appending_desc + article_text,
max_tokens = out_token,
temperature=0,
top_p=1.0,
frequency_penalty=0.0,
presence_penalty=0.0
)
# Print the generated summary
res = response["choices"][0]["text"]
st.success(res)
st.download_button('Download result', res)
except openai.error.APIError as e:
#Handle API error here, e.g. retry or log
print(f"OpenAI API returned an API Error: {e}")
pass
except openai.error.APIConnectionError as e:
#Handle connection error here
print(f"Failed to connect to OpenAI API: {e}")
pass
except openai.error.RateLimitError as e:
#Handle rate limit error (we recommend using exponential backoff)
print(f"OpenAI API request exceeded rate limit: {e}")
pass
else:
st.warning("Not enough words to correct the description!")
# For "Restaurant Reviews"
elif selected == "Restaurant Reviews":
st.subheader("Generate reviews for Restaurant / Cafe")
# Create Text Area Widget to enable user to enter texts
article_text = "Write a restaurant review based on these notes:\n\n"
st.text("Write a restaurant review based on these notes: Name: The Blue Wharf Lobster great, noisy, service polite, prices good.")
article_text1 = st.text_area("Name of the restaurant?")
article_text2 = st.text_area("Enter your short feedback")
article_text3 = st.text_input("Enter your desired name", 'John Doe')
# First, we'll use an if statement to determine the desired output size
# and set the out_token variable accordingly:
# Next, we'll add a check to make sure that the input text is long enough
# to summarize, and display a warning if it is not:
if len(article_text)>1:
if st.button("Generate Review",type='primary'):
pomm = "Your name is "+ article_text3 + ". " + article_text + "Name: " + article_text1 + "\n" + article_text2 + "\n\nReview:"
report = []
res_box = st.empty()
# Looping over the response
try:
for resp in openai.ChatCompletion.create(model="gpt-4o",
messages=[
{"role": "system", "content": "You are an AI assistant custom trained and created by Alpha AI. You are proficient at everytask."},
{"role": "user", "content": pomm}
],
max_tokens=64,
temperature = 0.6,
presence_penalty = 0.1,
frequency_penalty = 0.1,
stream = True):
# join method to concatenate the elements of the list
# into a single string,
# then strip out any empty strings
# print(resp)
if "content" in resp["choices"][0]["delta"]:
report.append(resp["choices"][0]["delta"]["content"])
# report.append(resp.choices[0].delta.content)
result = "".join(report).strip()
# result = result.replace("\n", "")
# st.success(f'{result}')
res_box.markdown(f'{result}')
else:
pass
st.text("Review by: " + article_text3)
# st.download_button('Download result', report)
# # Use GPT-3 to generate a summary of the article
# response = openai.Completion.create(
# engine="text-davinci-003",
# prompt= ,
# temperature=0.5,
# max_tokens=64,
# top_p=1.0,
# frequency_penalty=0.0,
# presence_penalty=0.0
# )
# # Print the generated summary
# res = response["choices"][0]["text"]
# st.success(res)
# st.download_button('Download result', res)
except openai.error.APIError as e:
#Handle API error here, e.g. retry or log
print(f"OpenAI API returned an API Error: {e}")
pass
except openai.error.APIConnectionError as e:
#Handle connection error here
print(f"Failed to connect to OpenAI API: {e}")
pass
except openai.error.RateLimitError as e:
#Handle rate limit error (we recommend using exponential backoff)
print(f"OpenAI API request exceeded rate limit: {e}")
pass
else:
st.warning("Not enough clarity to generate reviews!")
# IMAGE GENERATOR
elif selected == "Image Generator":
genre = st.radio(
"What type of content do you want to generate?",
('Dalle', 'Stable Diffusion'))
if genre == 'Dalle':
# Set up Streamlit app
st.subheader("Image Generator - Generating 4 Variants")
# Prompt user for image prompt
prompt = st.text_input("Enter image prompt:")
# Prompt user for image size
size = st.radio("Select image size:", list(image_sizes.keys()))
# Generate and display images
if st.button('Generate Image', type="primary"):
with st.spinner(text="Work in Progress... please wait"):
col1, col2 = st.columns(2)
with col1:
image1 = generate_image(prompt, image_sizes[size])
st.image(image1, caption="Generated image 1", use_column_width=True)
image3 = generate_image(prompt, image_sizes[size])
st.image(image3, caption="Generated image 3", use_column_width=True)
with col2:
image2 = generate_image(prompt, image_sizes[size])
st.image(image2, caption="Generated image 2", use_column_width=True)
image4 = generate_image(prompt, image_sizes[size])
st.image(image4, caption="Generated image 4", use_column_width=True)
# # Display images as a gallery
# images = [image1, image2, image3, image4]
# st.image(images, caption=["Generated image 1", "Generated image 2", "Generated image 3", "Generated image 4"], width=200)
else:
st.warning("Please enter an image prompt.")
st.text("Save Image by Right Click")
elif genre == 'Stable Diffusion':
st.write("Go to www.sdui.alphaai.biz to access the Stable Diffusion Toolkit!")
# BLOG GENERATOR
elif selected == "Blog Generator":
st.subheader('AI Blog Generator')
# st.text("Note: Audio will be only generated in the non-streaming mode.")
topic = st.text_input('Enter a topic to generate blog Topic on: ')
button_blogtopics = st.button('Generate Blog Topics', type="primary")
res_box1 = st.container()
if button_blogtopics:
st.markdown("----")
topic_ins = "Generate quality blog titles on " + str(topic)
res_box1.write(generate_content_blog(topic_ins))
st.markdown("----")
topic_blog = st.text_input('Enter a topic to generate blog outline and content on: ')
# stream_check = st.radio("Stream the result in realtime or view it in one go!",("NO Streaming","Streaming"))
if st.button("Submit", type="primary"):
st.markdown("----")
res_box2 = st.empty()
outline = "Generate a detailed blog on the topic " + str(topic_blog) + "."
report = []
# Looping over the response
try:
for resp in openai.ChatCompletion.create(model="gpt-4o",
messages=[
{
"role": "system", "content": """
Act as an expert blog writer. You write extremely well and long blogs. You take into account the SEO aspect of the content you write. Follow the context to generate blogs and keep in mind the number of characters specified in the context.
Context:
Add five keywords for each subheading.
Title
Write the title of the blog.
Write the Introduction to the blog in minimum 1500 characters.
Subheading
Generate content for subheading in minimum 1500 characters.
Subheading
Generate content for subheading in minimum 1500 characters.
Subheading
Generate content for subheading in minimum 1500 characters.
Subheading
Generate content for subheading in minimum 1500 characters.
Subheading
Generate content for subheading in minimum 1500 characters.
Conclusion
Write the conclusion to the blog in minimum 1000 characters.
"""},
{"role": "user", "content": outline}
],
max_tokens=3000,
temperature = 0.6,
presence_penalty = 0.1,
frequency_penalty = 0.1,
stream = True):
if "content" in resp["choices"][0]["delta"]:
report.append(resp["choices"][0]["delta"]["content"])
# report.append(resp.choices[0].delta.content)
result = "".join(report).strip()
# result = result.replace("\n", "")
res_box2.markdown(f'{result}')
else:
pass
except openai.error.APIError as e:
#Handle API error here, e.g. retry or log
print(f"OpenAI API returned an API Error: {e}")
pass
except openai.error.APIConnectionError as e:
#Handle connection error here
print(f"Failed to connect to OpenAI API: {e}")
pass
except openai.error.RateLimitError as e:
#Handle rate limit error (we recommend using exponential backoff)
print(f"OpenAI API request exceeded rate limit: {e}")
pass
# New tools 15th March 23
elif selected == "Content Paraphraser":
st.subheader('AI Content Paraphraser (Generation Limit - upto 5000 characters)')
# st.text("Note: Audio will be only generated in the non-streaming mode.")
topic = st.text_input('Enter content you would like to paraphrase')
if st.button("Submit", type="primary"):
res_box3 = st.empty()
outline = "Generate a detailed blog on the topic " + str(topic) + "."
report3 = []
# Looping over the response
try:
for resp in openai.ChatCompletion.create(model="gpt-4o",
messages=[
{
"role": "system", "content": "You are now ParaGPT. Your purpose is to paraphrase text. I will provide you with text, and then you will change up the words, the sentence structure, add or remove figurative language, etc and change anything necessary in order to paraphrase the text. However, it is extremely important you do not change the original meaning/significance of the text. "},
{"role": "user", "content": outline}
],
max_tokens=3000,
temperature = 0.6,
presence_penalty = 0.1,
frequency_penalty = 0.1,
stream = True):
if "content" in resp["choices"][0]["delta"]:
report3.append(resp["choices"][0]["delta"]["content"])
# report.append(resp.choices[0].delta.content)
result = "".join(report3).strip()
# result = result.replace("\n", "")
res_box3.markdown(f'{result}')
else:
pass
except openai.error.APIError as e:
#Handle API error here, e.g. retry or log
print(f"OpenAI API returned an API Error: {e}")
pass
except openai.error.APIConnectionError as e:
#Handle connection error here
print(f"Failed to connect to OpenAI API: {e}")
pass
except openai.error.RateLimitError as e:
#Handle rate limit error (we recommend using exponential backoff)
print(f"OpenAI API request exceeded rate limit: {e}")
pass
elif selected == "Story Teller":
st.subheader('AI Story Teller (Generation Limit - upto 5000 characters)')
# st.text("Note: Audio will be only generated in the non-streaming mode.")
topic = st.text_area('Enter the topic for generating the story.', max_chars = 500)
if st.button("Submit", type="primary"):
res_box4 = st.empty()
outline = "I want you to act as a storyteller. You will come up with entertaining stories that are engaging, imaginative and captivating for the audience. It can be fairy tales, educational stories or any other type of stories which has the potential to capture people's attention and imagination. Depending on the target audience, you may choose specific themes or topics for your storytelling session. Now i want you to write about " + str(topic) + "."
report4 = []
# Looping over the response
try:
for resp in openai.ChatCompletion.create(model="gpt-4o",
messages=[
{"role": "user", "content": outline}
],
max_tokens=3000,
temperature = 0.6,
presence_penalty = 0.1,
frequency_penalty = 0.1,
stream = True):
if "content" in resp["choices"][0]["delta"]:
report4.append(resp["choices"][0]["delta"]["content"])
# report.append(resp.choices[0].delta.content)
result = "".join(report4).strip()
# result = result.replace("\n", "")
res_box4.markdown(f'{result}')
else:
pass
except openai.error.APIError as e:
#Handle API error here, e.g. retry or log
print(f"OpenAI API returned an API Error: {e}")
pass
except openai.error.APIConnectionError as e:
#Handle connection error here
print(f"Failed to connect to OpenAI API: {e}")
pass
except openai.error.RateLimitError as e:
#Handle rate limit error (we recommend using exponential backoff)
print(f"OpenAI API request exceeded rate limit: {e}")
pass
elif selected == "Social Media Copywriting":
st.subheader('AI Social Media Copywriting (Generation Limit - upto 5000 characters)')
# st.text("Note: Audio will be only generated in the non-streaming mode.")
social_plat = st.radio("Which platform",('LinkedIn', 'Instagram', 'Facebook'))
purpose = st.text_area('Purpose of the post. Be explicit.')
keywords = st.text_input("Enter the required keywords in a comma separated form.", value = "Eg. Abc, Def, Ghi...")
rules = st.text_input("Enter the required rules to follow to make the post in a comma separated form.")
outline_smc = "Create a compelling, eye-catching " + social_plat + "post for " + purpose + "." + "The post should include " + keywords + ". " + "Also, it should follow these rules: " + rules + "."
if st.button("Submit", type="primary"):
res_box5 = st.empty()
report5 = []
# Looping over the response
try:
for resp in openai.ChatCompletion.create(model="gpt-4o",
messages=[
{"role": "user", "content": outline_smc}
],
max_tokens=3000,
temperature = 0.6,
presence_penalty = 0.1,
frequency_penalty = 0.1,
stream = True):
if "content" in resp["choices"][0]["delta"]:
report5.append(resp["choices"][0]["delta"]["content"])
# report.append(resp.choices[0].delta.content)
result = "".join(report5).strip()
# result = result.replace("\n", "")
res_box5.markdown(f'{result}')
else:
pass
except openai.error.APIError as e:
#Handle API error here, e.g. retry or log
print(f"OpenAI API returned an API Error: {e}")
pass
except openai.error.APIConnectionError as e:
#Handle connection error here
print(f"Failed to connect to OpenAI API: {e}")
pass
except openai.error.RateLimitError as e:
#Handle rate limit error (we recommend using exponential backoff)
print(f"OpenAI API request exceeded rate limit: {e}")
pass
elif selected == "Marketing Campaign":
st.subheader('Generate content for various marketing scenarios.')
option = st.selectbox('What would you like to do today??',
(
'Act As An Advertiser',
'Write AIDAs',
'Instagram Caption',
'Persuasive Texts',
'Influencer Marketing Campaign',
'Emotional Appeal Campaign',
'Instagram Story Ideas',
'Generate video script',
'Lean Startup Methodology'
))
if option =="Act As An Advertiser":
prompt_adv1 = "I want you to act as an advertiser. You will create a campaign to promote a product or service of your choice. You will choose a target audience, develop key messages and slogans, select the media channels for promotion, and decide on any additional activities needed to reach your goals. My first suggestion request is "
prompt_adv2 = st.text_input("What do you need an advertising campaign for?")
final_pmt = prompt_adv1 + prompt_adv2
elif option =="Write AIDAs":
st.text("AIDAS stands for Attention, Interest, Desire, Action, and Satisfaction.")
prompt_aidas = "Write an AIDA for "
input_aidas = st.text_input("Enter the topic to generate it AIDAs")
final_pmt = prompt_aidas + input_aidas
elif option =='Instagram Caption':
prompt_ic = "Write an attractive Instagram Caption "
input_ic = st.text_input("Insert Product description...")
final_pmt = prompt_ic + input_ic
elif option =='Persuasive Texts':
option_text = st.selectbox('Choose the type of text:',('Copy','Email','Blog','Newsletter','Article'))
# type_of_text = st.text_input("Type of persuasiveness, elaborate.")
ideal_customer_persona = st.text_input("Please elaborate on your ideal customer persona.")
type_of_prod = st.text_input("Elaborate on the type of product/program/subscription.")
prompt_ic = "I'm looking for a " + option_text + "that will convince " + ideal_customer_persona + " to sign up for my " + type_of_prod + "by explaining the value it brings and the benefits they'll receive."
final_pmt = prompt_ic
elif option =='Influencer Marketing Campaign':
type_of_content = st.text_input("Type of content needed from the influencer.")
ideal_customer_persona = st.text_input("Please elaborate on your ideal customer persona.")
type_of_prod = st.text_input("Elaborate on the type of product/program/subscription.")
influencer_type = st.text_input("Tell us a bit about your ideal type of influencer.")
final_pmt = "I need an influencer marketing campaign outline that will engage my "+ ideal_customer_persona+ " with " + type_of_content + " from " + influencer_type + " who can showcase the unique features and benefits of our " + type_of_prod + " in a fun and creative way."
elif option =='Emotional Appeal Campaign':
emotional_appeal = st.text_input("Describe the type of emotional appeal.")
ideal_customer_persona = st.text_input("Please elaborate on your ideal customer persona.")
type_of_prod = st.text_input("Elaborate on the type of product/program/subscription.")
type_of_emotion = st.text_input("List down ',' seperated emotions ideal for your campaign.")
prompt_ea = "Using the 'Emotional Appeal' framework, please write a marketing campaign outline that uses "+ emotional_appeal + " to persuade "+ ideal_customer_persona + "to take action and purchase our " + type_of_prod + ". Choose any of the emotions such as " + type_of_emotion + "."
final_pmt = prompt_ea
elif option =='Instagram Story Ideas':
ideal_customer_persona = st.text_input("Please elaborate on your ideal customer persona.")
prompt_is = "I need an Instagram story idea that will provide a sneak peek of upcoming products or services and create a sense of anticipation and excitement for my "+ ideal_customer_persona +" with a clear and compelling call to action."
final_pmt = prompt_is
elif option =='Generate video script':
duration = st.text_input("Enter the duration of the required video.", value = "Eg. 4 minutes or 30 second")
type_of_prod = st.text_input("Elaborate on the type of product/program/subscription.")
prompt_gvs = "Generate an " + duration + " video script for a YouTube and Instagram video about our newest " + type_of_prod
final_pmt = prompt_gvs
elif option =='Lean Startup Methodology':
rules = st.text_input("Please describe your product or service.")
ideal_customer = st.text_input("Please describe your ideal customer.")
outline_smc = "Outline a marketing campaign using the 'Lean Startup Methodology' framework that employs rapid experimentation and iteration to identify a scalable business model for our " + rules + "that appeals to our " + ideal_customer + ". Explain the steps taken to validate assumptions and obtain customer feedback to guide the marketing strategy."
final_pmt = outline_smc
else:
st.text("Please select an option!")
if st.button("Submit", type="primary"):
res_box6 = st.empty()
report6 = []
# Looping over the response
try:
for resp in openai.ChatCompletion.create(model="gpt-4o",
messages=[
{
"role": "system", "content": "Act As An AI Advertiser custom trained and created by Alpha AI. You are proficient at everytask.",
"role": "user", "content": final_pmt
}
],
max_tokens=4000,
temperature = 0.7,
presence_penalty = 0.1,
frequency_penalty = 0.1,
stream = True):
if "content" in resp["choices"][0]["delta"]:
report6.append(resp["choices"][0]["delta"]["content"])
# report.append(resp.choices[0].delta.content)
result = "".join(report6).strip()
# result = result.replace("\n", "")
res_box6.markdown(f'{result}')
else:
pass
except openai.error.APIError as e:
#Handle API error here, e.g. retry or log
print(f"OpenAI API returned an API Error: {e}")
pass
except openai.error.APIConnectionError as e:
#Handle connection error here
print(f"Failed to connect to OpenAI API: {e}")
pass
except openai.error.RateLimitError as e:
#Handle rate limit error (we recommend using exponential backoff)
print(f"OpenAI API request exceeded rate limit: {e}")
pass
# New tools 15th March 23
elif selected == "PPT Generator":
st.subheader("PPT Generator")
topic = st.text_input('Enter a relevant topic')
# api_key = st.text_input('Enter your API key')
slides_sst = st.slider("Select the number of slides:", 1, 20, 5)
slide_color = st.selectbox("Select the background color of the presentation:", ["White", "Black", "Red", "Green", "Blue"], key = "sbox1")
# Convert the selected color to lowercase
slide_colors = slide_color.lower()
font_color = st.selectbox("Select the color of the font:", ["White", "Black", "Red", "Green", "Blue"], key = "sbox2")
# Convert the selected color to lowercase
font_colors = font_color.lower()
button_blogtopics = st.button('Generate', type="primary")
if button_blogtopics:
st.text("Please wait for your slides to be made and displayed")
b,binary_output = generate_ppt(topic, slides_sst,slide_colors,font_colors)
st.markdown(b)
string_path = b
st.markdown("----")
# f_path = Path(b)
# print(type(f_path))
path = os.path.normpath(b)
list_files = subprocess.run(["libreoffice","--headless","--convert-to","pdf","--outdir", "output/",path])
print("The exit code was: %d" % list_files.returncode)
# PDF Path
string_path = string_path[:-5]
string_path = string_path[6:]
string_path = "output/" + string_path + ".pdf"
path_pdf = os.path.normpath(string_path)
def show_pdf(file_val = path_pdf):
with open(file_val,"rb") as f:
base64_pdf = base64.b64encode(f.read()).decode('utf-8')
pdf_display = f'<iframe src="data:application/pdf;base64,{base64_pdf}" width="800" height="800" type="application/pdf"></iframe>'
st.markdown(pdf_display, unsafe_allow_html=True)
show_pdf(path_pdf)
st.download_button(label='Click to download PowerPoint',data=binary_output.getvalue(),file_name=path)
# Legal assistant
elif selected == "AD Generator":
st.subheader("Generate ADs using alphaGPT")
st.success("The uploaded image should be in 1:1 ratio else it will result in an error.")
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
if uploaded_file is not None:
# Read the uploaded image and display it
image = Image.open(uploaded_file)
# st.image(image, caption="Original Image", use_column_width=True)
output_path = 'output_dalle_image.png'
output_path2 = 'output_dalle_image2.png'
input_save = 'input_dalle_img.png'
image.save(input_save)
# input = Image.open(input_path),False,240,10,20,None,False,False
output2 = remove(image, only_mask=True)
# output = remove(image,alpha_matting=True)
output = remove(image)
output.save(output_path)
output2.save(output_path2)
# Display the original and processed images side by side
col1, col2, col3 = st.columns(3)
with col1:
st.image(image, caption="Original Image", use_column_width=True)
with col2:
st.image(output, caption="Masked Foreground", use_column_width=True)
with col3:
st.image(output2, caption="Masked Background", use_column_width=True)
# Create Radio Buttons
output_mask_selected = st.radio( label = "What type of mask",
options= ["Masked Foreground", "Masked Background"]
)
if output_mask_selected == "Masked Foreground":
mask_img = output_path
elif output_mask_selected == "Masked Background":
mask_img = output_path2
# Prompt user for image prompt
prompt = st.text_input("Enter image prompt:")
# Prompt user for image size
size = st.radio("Select image size:", list(image_sizes.keys()))
input_img = input_save
# mask_img = output_path
# Generate and display images
if st.button('Generate Image', type="primary"):
with st.spinner(text="Work in Progress... please wait"):
col1, col2 = st.columns(2)
with col1:
image1 = generate_image_edit_dalle(prompt, image_sizes[size],input_img,mask_img)
st.image(image1, caption="Generated image 1", use_column_width=True)
image3 = generate_image_edit_dalle(prompt, image_sizes[size],input_img,mask_img)
st.image(image3, caption="Generated image 2", use_column_width=True)
image5 = generate_image_edit_dalle(prompt, image_sizes[size],input_img,mask_img)
st.image(image5, caption="Generated image 3", use_column_width=True)
with col2:
image2 = generate_image_edit_dalle(prompt, image_sizes[size],input_img,mask_img)
st.image(image2, caption="Generated image 4", use_column_width=True)
image4 = generate_image_edit_dalle(prompt, image_sizes[size],input_img,mask_img)
st.image(image4, caption="Generated image 5", use_column_width=True)
image6 = generate_image_edit_dalle(prompt, image_sizes[size],input_img,mask_img)
st.image(image6, caption="Generated image 6", use_column_width=True)
# # Display images as a gallery
# images = [image1, image2, image3, image4]
# st.image(images, caption=["Generated image 1", "Generated image 2", "Generated image 3", "Generated image 4"], width=200)
else:
st.warning("Please enter an image prompt.")
st.warning("Here are some examples for the prompts!")
st.info("Beautiful pond surrounded by lavender and lilac, dappled sunbeams illuminating the scene, stunning photograph from lansdcaping magazine.")
st.info("A digital illustration of glowing toadstools beside a pond with lilypads, 4k, detailed, trending in artstation")
st.info("An oil painting of a mechanical clockwork flying machine from the renaissance, Gorgeous digital painting, amazing art, artstation 3, realistic")
st.info("Rubber Duck Aliens visiting the Earth for the first time, hyper-realistic, cinematic, detailed")
st.info("photo of an extremely cute alien fish swimming an alien habitable underwater planet, coral reefs, dream-like atmosphere, water, plants, peaceful, serenity, calm ocean, tansparent water, reefs, fish, coral, inner peace, awareness, silence, nature, evolution --version 3 --s 42000 --uplight --no text, blur")
st.info("2 medieval warriors ::0.4 travelling on a cliff to a background castle , view of a coast line landscape , English coastline, Irish coastline, scottish coastline, perspective, folklore, King Arthur, Lord of the Rings, Game of Thrones. Photographic, Photography, photorealistic, concept art, Artstation trending , cinematic lighting, cinematic composition, rule of thirds , ultra-detailed, dusk sky , low contrast, natural lighting, fog, realistic, light fogged, detailed, atmosphere hyperrealistic , volumetric light, ultra photoreal, | 35mm| , Matte painting, movie concept art, hyper-detailed, insanely detailed, corona render, octane render, 8k --no blur")
elif selected == "Legal Aid":
# Define the categories and options
categories = ['Legal Research', 'Drafting Legal Documents', 'Contract Drafting', 'Legal Forms and Documents', 'Legal Analysis','Legal Writing','Client Questions','Legal Procedures','Legal Terminology','Legal Citations']
options = {
'Legal Research': [
"Provide examples of [legal case/issue]",
"What are the latest developments in [legal area]?",
"What are the relevant laws or regulations regarding [legal issue]?",
"What is the history of [legal case/issue]?",
"What is the legal definition of [legal term or phrase]",
"What is the legal precedent for [legal case/issue]?",
"What are the pros and cons of [legal argument/position]?",
"What is the standard for [legal issue] in [jurisdiction]?",
"What are the key legal arguments in [legal case/issue]?",
"Provide a summary of [case name]",
"Summarize the following contract: [copy and paste contract]",
"What is the statute of limitations for [type of case] in [state or jurisdiction]?",
"Outline the steps involved in [legal process or procedure]",
"What is the significance of [case name]?"
],
'Drafting Legal Documents': [
"Draft a [legal document type] for [legal scenario]",
"Draft a [legal document type] for [party 1] and [party 2]",
"Write a [legal document type] for [legal issue]",
"Write a [legal document type] for [client name]",
"What should be included in a [legal document type]?",
"What are the standard clauses for [legal document type]?",
"What are the necessary elements for [legal document type]?",
"What are the typical terms for [legal document type]?",
"What are the recommended provisions for [legal document type]?",
"Provide a template for [legal document name]",
"What are the most common mistakes to avoid when drafting a [legal document name]?"
],
'Contract Drafting': [
"Draft a [contract type] between [party 1] and [party 2] for [consideration]",
"Draft a non-disclosure agreement (NDA) between [party 1] and [party 2]",
"Draft a confidentiality agreement between [party 1] and [party 2]",
"Draft an employment contract for [position] with [salary and benefits information]",
"Draft a service agreement between [party 1] and [party 2]",
"Draft a lease agreement for [property description]",
"Draft a purchase agreement for [item/property description]"
],
'Legal Forms and Documents': [
"Draft a power of attorney form",
"Draft a will",
"Draft a living trust",
"Draft a contract for [contract type]",
"Draft a non-disclosure agreement (NDA)",
"Draft a confidentiality agreement",
"Draft an employment contract",
"Draft a partnership agreement",
"Draft a prenuptial agreement",
"Draft a divorce agreement",
"Draft a property settlement agreement"
],
'Legal Analysis': [
"What are the strengths and weaknesses of [legal argument]?",
"What are the possible outcomes of [legal issue]?",
"What is the likelihood of [legal outcome]?",
"What is the impact of [legal issue] on [affected parties]?",
"What are the alternative solutions for [legal issue]?",
"What is the best course of action for [legal issue]?",
"What are the risks associated with [legal issue]?",
"What is the likelihood of success for [legal issue]?",
"What is the legal basis for [legal argument]?",
"What is the legal precedent for [legal argument]?",
"What are the legal arguments for and against [legal issue]?"
],
'Legal Writing':[
"Write a memo on [legal issue]",
"Write a brief on [legal issue]",
"Rephrase this clause: [clause]",
"Write an argument for [legal issue]",
"Write a legal opinion on [legal issue]",
"What is the appropriate tone for [legal writing type]?",
"What is the standard structure for [legal writing type]?",
"What are the key points to include in [legal writing type]?",
"What are the persuasive strategies for [legal writing type]?",
"What is the format for [legal writing type]?",
"Proofread the following: [copy and paste contract]",
"What are the best practices for [legal writing type]?"
],
'Client Questions':[
"What is the best way to [legal issue]?",
"What are the options for [legal issue]?",
"What is the process for [legal issue]?",
"What are the costs associated with [legal issue]?",
"What is the estimated time frame for [legal issue] resolution?",
"What is the likelihood of success for [legal issue]?",
"What are the potential consequences of [legal issue]?",
"What are the necessary steps to take for [legal issue]?",
"What are the legal requirements for [legal issue]?",
"What is the most common outcome for [legal issue]?"
],
'Legal Procedures':[
"What is the proper procedure for [legal action] in [jurisdiction]?",
"What are the necessary forms for [legal action] in [jurisdiction]?",
"What is the filing deadline for [legal action] in [jurisdiction]?",
"What is the fee for [legal action] in [jurisdiction]?",
"What is the estimated time frame for [legal action] in [jurisdiction]?",
"What is the expected outcome for [legal action] in [jurisdiction]?",
],
'Legal Terminology':[
"What is the context in which [legal term] is typically used?",
"What is the origin of [legal term]?",
"What are the synonyms of [legal term]?",
"What are the related terms to [legal term]?",
"What is the meaning of [legal term]?",
"What is the difference between [legal term 1] and [legal term 2]?",
"What is the definition of [legal term] in [jurisdiction]?",
"What is the explanation of [legal form or document]",
"What are the benefits of using [legal form or document]",
"What are the requirements for [legal form or document] in [jurisdiction]"
],
'Legal Citations':[
"What is the correct format for a [citation style] citation of [legal source]?",
"What is the [citation style] citation for [legal case]?",
"What is the [citation style] citation for [legal statute]?",
"What is the [citation style] citation for [legal regulation]?",
"What is the [citation style] citation for [legal treatise]?"
]
}
image_law = "law.png"
col1, col2 = st.columns([1,3])
with col2:
st.title('Legal Information Finder')
with col1:
st.image(image_law,width=120)
# Select a category
category = st.selectbox("Select a category", categories)
# Select an option
option = st.selectbox(f"Select an option for {category}", options[category])
# Get user input
prompt = st.text_area(f"Prompt editor", value = option)
# Generate text using OpenAI API
if st.button("Submit", type="primary"):
with st.spinner(text="Generating text..."):
text = generate_legal_content(prompt)
# st.write("Generated text:")
st.write(text)
ext = dt = datetime.now()
result_aud6 = text_to_speech(f"{text}",ext)
audio_file = open(f"temp/{result_aud6}.mp3", "rb")
audio_bytes = audio_file.read()
st.markdown(f"Your audio:")
st.audio(audio_bytes, format="audio/mp3", start_time=0)
elif selected == "Travel and Tourism":
st.subheader('AI Toolkit - Travel & Tourism.')
st.text("travel-oriented things including planning trips, setting aside budgets, suggesting places, and a lot more.")
option = st.selectbox('What would you like to do today??',
(
'Travel Guide',
'Suggest Landmarks',
'Imagine your destination',
'Plan trips',
'Detailed location suggestions'
))
if option =="Travel Guide":
prompt_adv1 = "I want you to act as a travel guide. I will write you my location and you will suggest places to visit near my location. In some cases, I will also give you the type of places I will visit. You will also suggest me places of a similar type that are close to my first location. My first suggestion request is "
prompt_adv2 = st.text_input("Enter location and purpose and a nearby places would be recommended to you.", value = "I am in London and I want to visit only museums.")
final_pmt = prompt_adv1 + prompt_adv2
elif option =="Suggest Landmarks":
place_visit = st.text_input("Enter the place of visit.")
country_visit = st.text_input("Enter the country where that place exists.")
prompt_aidas = "I'm planning on visiting " + place_visit + " in "+ country_visit + ". What are some of the landmarks I must see?"
final_pmt = prompt_aidas
elif option =='Imagine your destination':
prompt_ic = "I want you to act as my time travel guide. I will provide you with the historical period or future time I want to visit and you will suggest the best events, sights, or people to experience. Do not write explanations, simply provide suggestions and any necessary information. My first request is "
input_ic = st.text_input("Quote a request based on the example value...", value = "I want to visit the Renaissance period, can you suggest some interesting events, sights, or people for me to experience?")
final_pmt = prompt_ic + input_ic
elif option =='Plan trips':
st.subheader('Let us plan your trip!')
# Form for User Input
st.subheader('Budget')
budget = st.text_input("Enter your travel budget.", value = "$2000 dollars")
st.subheader('Destination')
destination = st.text_input('Destination', value='Eg. Dubai')
st.subheader('Arriving from')
source = st.text_input('Source', value='Eg. Mumbai')
st.subheader('Duration')
duration = st.text_input("Duration of the travel.", value = "4 days")
add_info = st.text_area('Additional Information', height=200, value='I want to visit as many places as possible! (respect time)')
final_pmt = "I have " + budget + " and travelling for " + duration + ". Plan a trip for me to " + destination + " from " + source + ". Please take into account the additional information as well which is " + add_info
elif option =='Detailed location suggestions':
st.text("Simply follow the value inside the textbox as an example...")
type_of_content = st.text_input("Prompt", value = "I'm planning on visiting the UK for 20 days. Give me 10 cities I should visit while there.")
final_pmt = type_of_content
elif option =='General travel tips':
st.text("Simply follow the value inside the textbox as an example...")
type_of_content = st.text_input("Prompt", value = "What is the best time of year to visit Hawaii?")
final_pmt = type_of_content
else:
st.text("Please select an option!")
if st.button("Submit", type="primary"):
res_box6 = st.empty()
report6 = []
# Looping over the response
try:
for resp in openai.ChatCompletion.create(model="gpt-4o",
messages=[
{
"role": "system", "content": "You are an AI Language model custom trained and created by Alpha AI. You are proficient at everytask.",
"role": "user", "content": final_pmt
}
],
max_tokens=4000,
temperature = 0.7,
presence_penalty = 0.1,
frequency_penalty = 0.1,
stream = True):
if "content" in resp["choices"][0]["delta"]:
report6.append(resp["choices"][0]["delta"]["content"])
# report.append(resp.choices[0].delta.content)
result = "".join(report6).strip()
# result = result.replace("\n", "")
res_box6.markdown(f'{result}')
else:
pass
except openai.error.APIError as e:
#Handle API error here, e.g. retry or log
print(f"OpenAI API returned an API Error: {e}")
pass
except openai.error.APIConnectionError as e:
#Handle connection error here
print(f"Failed to connect to OpenAI API: {e}")
pass
except openai.error.RateLimitError as e:
#Handle rate limit error (we recommend using exponential backoff)
print(f"OpenAI API request exceeded rate limit: {e}")
pass
elif selected == "Document Chat":
st.subheader("Chat with your document!")
st.markdown(
"""
#### π¨οΈ Chat with your PDF files π with `Conversational Buffer Memory`
> *powered by [LangChain]('https://langchain.readthedocs.io/en/latest/modules/memory.html#memory') +
[OpenAI]('https://platform.openai.com/docs/models/gpt-3-5') + [DataButton](https://www.databutton.io/)*
----
"""
)
st.markdown(
"""
`openai`
`langchain`
`tiktoken`
`pypdf`
`faiss-cpu`
---------
"""
)
# # Set up the sidebar
# st.sidebar.markdown(
# """
# ### Steps:
# 1. Upload PDF File
# 2. Enter Your Secret Key for Embeddings
# 3. Perform Q&A
# **Note : File content and API key not stored in any form.**
# """
# )
# Allow the user to upload a PDF file
uploaded_file = st.file_uploader("**Upload Your PDF File**", type=["pdf"])
if uploaded_file:
name_of_file = uploaded_file.name
doc = parse_pdf(uploaded_file)
pages = text_to_docs(doc)
if pages:
# Allow the user to select a page and view its content
with st.expander("Show Page Content", expanded=False):
page_sel = st.number_input(
label="Select Page", min_value=1, max_value=len(pages), step=1
)
pages[page_sel - 1]
# Allow the user to enter an OpenAI API key
# api = st.text_input(
# "**Enter OpenAI API Key**",
# type="password",
# placeholder="sk-",
# help="https://platform.openai.com/account/api-keys",
# )
api = openai.api_key
if api:
# Test the embeddings and save the index in a vector database
index = test_embed()
# Set up the question-answering system
qa = RetrievalQA.from_chain_type(
llm=OpenAI(openai_api_key=api),
chain_type = "map_reduce",
retriever=index.as_retriever(),
)
# Set up the conversational agent
tools = [
Tool(
name="Indian Legal QA System",
func=qa.run,
description="Useful for when you need to answer questions about the aspects asked. Input may be a partial or fully formed question.",
)
]
prefix = """Have a conversation with a human, answering the following questions as best you can based on the context and memory available.
You have access to a single tool:"""
suffix = """Begin!"
{chat_history}
Question: {input}
{agent_scratchpad}"""
prompt = ZeroShotAgent.create_prompt(
tools,
prefix=prefix,
suffix=suffix,
input_variables=["input", "chat_history", "agent_scratchpad"],
)
if "memory" not in st.session_state:
st.session_state.memory = ConversationBufferMemory(
memory_key="chat_history"
)
llm_chain = LLMChain(
llm=OpenAI(
temperature=0, openai_api_key=api, model_name="gpt-4o"
),
prompt=prompt,
)
agent = ZeroShotAgent(llm_chain=llm_chain, tools=tools, verbose=True)
agent_chain = AgentExecutor.from_agent_and_tools(
agent=agent, tools=tools, verbose=True, memory=st.session_state.memory
)
# Allow the user to enter a query and generate a response
query = st.text_input(
"**What's on your mind?**",
placeholder="Ask me anything from {}".format(name_of_file),
)
if query:
with st.spinner(
"Generating Answer to your Query : `{}` ".format(query)
):
res = agent_chain.run(query)
st.info(res, icon="π€")
# Allow the user to view the conversation history and other information stored in the agent's memory
with st.expander("History/Memory"):
st.session_state.memory |