Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,7 @@ from PIL import Image
|
|
9 |
from streamlit_image_comparison import image_comparison
|
10 |
import numpy as np
|
11 |
import re
|
|
|
12 |
#import chromadb
|
13 |
|
14 |
from textwrap import dedent
|
@@ -378,6 +379,153 @@ with tab2:
|
|
378 |
st.error("Please enter some text to convert.")
|
379 |
|
380 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
381 |
st.header("Custom GPT Engineering Tools")
|
382 |
st.link_button("Conversation Analyzer", "https://chat.openai.com/g/g-XARuyBgpL-conversation-analyzer")
|
383 |
|
|
|
9 |
from streamlit_image_comparison import image_comparison
|
10 |
import numpy as np
|
11 |
import re
|
12 |
+
import cohere
|
13 |
#import chromadb
|
14 |
|
15 |
from textwrap import dedent
|
|
|
379 |
st.error("Please enter some text to convert.")
|
380 |
|
381 |
|
382 |
+
cohere_api_key = os.environ.get('COHERE_API_KEY') # Fetch the API key from environment variable
|
383 |
+
|
384 |
+
if cohere_api_key is None:
|
385 |
+
st.error("API key not found. Please set the COHERE_API_KEY environment variable.")
|
386 |
+
st.stop()
|
387 |
+
|
388 |
+
# Get API Key Here - https://dashboard.cohere.com/api-keys
|
389 |
+
|
390 |
+
co = cohere.Client(cohere_api_key) # Use the fetched API key
|
391 |
+
|
392 |
+
def generate_text(prompt, model='c4ai-aya', max_tokens=300, temperature=0.4):
|
393 |
+
response = co.generate(
|
394 |
+
model=model,
|
395 |
+
prompt=prompt,
|
396 |
+
max_tokens=max_tokens,
|
397 |
+
temperature=temperature,
|
398 |
+
k=0,
|
399 |
+
stop_sequences=[],
|
400 |
+
return_likelihoods='NONE')
|
401 |
+
return response.generations[0].text
|
402 |
+
|
403 |
+
# Streamlit interface
|
404 |
+
st.title("Text Generation with Cohere")
|
405 |
+
|
406 |
+
lang_id = {
|
407 |
+
"Afrikaans": "af",
|
408 |
+
"Amharic": "am",
|
409 |
+
"Arabic": "ar",
|
410 |
+
"Asturian": "ast",
|
411 |
+
"Azerbaijani": "az",
|
412 |
+
"Bashkir": "ba",
|
413 |
+
"Belarusian": "be",
|
414 |
+
"Bulgarian": "bg",
|
415 |
+
"Bengali": "bn",
|
416 |
+
"Breton": "br",
|
417 |
+
"Bosnian": "bs",
|
418 |
+
"Catalan": "ca",
|
419 |
+
"Cebuano": "ceb",
|
420 |
+
"Czech": "cs",
|
421 |
+
"Welsh": "cy",
|
422 |
+
"Danish": "da",
|
423 |
+
"German": "de",
|
424 |
+
"Greeek": "el",
|
425 |
+
"English": "en",
|
426 |
+
"Spanish": "es",
|
427 |
+
"Estonian": "et",
|
428 |
+
"Persian": "fa",
|
429 |
+
"Fulah": "ff",
|
430 |
+
"Finnish": "fi",
|
431 |
+
"French": "fr",
|
432 |
+
"Western Frisian": "fy",
|
433 |
+
"Irish": "ga",
|
434 |
+
"Gaelic": "gd",
|
435 |
+
"Galician": "gl",
|
436 |
+
"Gujarati": "gu",
|
437 |
+
"Hausa": "ha",
|
438 |
+
"Hebrew": "he",
|
439 |
+
"Hindi": "hi",
|
440 |
+
"Croatian": "hr",
|
441 |
+
"Haitian": "ht",
|
442 |
+
"Hungarian": "hu",
|
443 |
+
"Armenian": "hy",
|
444 |
+
"Indonesian": "id",
|
445 |
+
"Igbo": "ig",
|
446 |
+
"Iloko": "ilo",
|
447 |
+
"Icelandic": "is",
|
448 |
+
"Italian": "it",
|
449 |
+
"Japanese": "ja",
|
450 |
+
"Javanese": "jv",
|
451 |
+
"Georgian": "ka",
|
452 |
+
"Kazakh": "kk",
|
453 |
+
"Central Khmer": "km",
|
454 |
+
"Kannada": "kn",
|
455 |
+
"Korean": "ko",
|
456 |
+
"Luxembourgish": "lb",
|
457 |
+
"Ganda": "lg",
|
458 |
+
"Lingala": "ln",
|
459 |
+
"Lao": "lo",
|
460 |
+
"Lithuanian": "lt",
|
461 |
+
"Latvian": "lv",
|
462 |
+
"Malagasy": "mg",
|
463 |
+
"Macedonian": "mk",
|
464 |
+
"Malayalam": "ml",
|
465 |
+
"Mongolian": "mn",
|
466 |
+
"Marathi": "mr",
|
467 |
+
"Malay": "ms",
|
468 |
+
"Burmese": "my",
|
469 |
+
"Nepali": "ne",
|
470 |
+
"Dutch": "nl",
|
471 |
+
"Norwegian": "no",
|
472 |
+
"Northern Sotho": "ns",
|
473 |
+
"Occitan": "oc",
|
474 |
+
"Oriya": "or",
|
475 |
+
"Panjabi": "pa",
|
476 |
+
"Polish": "pl",
|
477 |
+
"Pushto": "ps",
|
478 |
+
"Portuguese": "pt",
|
479 |
+
"Romanian": "ro",
|
480 |
+
"Russian": "ru",
|
481 |
+
"Sindhi": "sd",
|
482 |
+
"Sinhala": "si",
|
483 |
+
"Slovak": "sk",
|
484 |
+
"Slovenian": "sl",
|
485 |
+
"Somali": "so",
|
486 |
+
"Albanian": "sq",
|
487 |
+
"Serbian": "sr",
|
488 |
+
"Swati": "ss",
|
489 |
+
"Sundanese": "su",
|
490 |
+
"Swedish": "sv",
|
491 |
+
"Swahili": "sw",
|
492 |
+
"Tamil": "ta",
|
493 |
+
"Thai": "th",
|
494 |
+
"Tagalog": "tl",
|
495 |
+
"Tswana": "tn",
|
496 |
+
"Turkish": "tr",
|
497 |
+
"Ukrainian": "uk",
|
498 |
+
"Urdu": "ur",
|
499 |
+
"Uzbek": "uz",
|
500 |
+
"Vietnamese": "vi",
|
501 |
+
"Wolof": "wo",
|
502 |
+
"Xhosa": "xh",
|
503 |
+
"Yiddish": "yi",
|
504 |
+
"Yoruba": "yo",
|
505 |
+
"Chinese": "zh",
|
506 |
+
"Zulu": "zu",
|
507 |
+
}
|
508 |
+
|
509 |
+
|
510 |
+
# Text input
|
511 |
+
user_input = st.text_area("Enter your text", " Hi Mohammed, it is nice to meet you. Let's discuss how to be better friends and tackle the world's issues such as global warming and climate change together. There are already so many technology solutions in this grand city that can be applied to the world. I am glad to be working on this problem with you.")
|
512 |
+
|
513 |
+
# Language selection - for demonstration purposes only
|
514 |
+
# In a real translation scenario, you'd use actual language codes and a translation model
|
515 |
+
|
516 |
+
source_lang = st.selectbox(label="Source language", options=list(lang_id.keys()))
|
517 |
+
target_lang = st.selectbox(label="Target language", options=list(lang_id.keys()))
|
518 |
+
|
519 |
+
|
520 |
+
# Button to generate text
|
521 |
+
if st.button("Generate"):
|
522 |
+
prompt = f"Translate the following {source_lang} text to {target_lang}: " + user_input + " ONLY TRANSLATE DON'T ADD ANY ADDITIONAL DETAILS"
|
523 |
+
|
524 |
+
# Generate text
|
525 |
+
output = generate_text(prompt)
|
526 |
+
st.text_area("Generated Text", output, height=300)
|
527 |
+
|
528 |
+
|
529 |
st.header("Custom GPT Engineering Tools")
|
530 |
st.link_button("Conversation Analyzer", "https://chat.openai.com/g/g-XARuyBgpL-conversation-analyzer")
|
531 |
|