File size: 1,297 Bytes
275496d
 
 
 
6ddf70c
275496d
 
3f02e63
275496d
 
 
54ed8be
275496d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import logging
logging.basicConfig(level=logging.DEBUG)

import streamlit as st
import os
from openai import OpenAI

API_Key= os.getenv("OPENAI_API_KEY")
# generateContext = pipeline("text-generation", model="meta-llama/Llama-3.1-405B-Instruct")

client = OpenAI(base_url = "https://integrate.api.nvidia.com/v1",
  api_key = API_Key
)

def main():
    st.title("Context Analyzer")
    st.write("This app analyzes the context of the text you input and provides a detailed explanation.")
    content = st.text_input("Please input a text:")

    
    if st.button("Get Context"):
        if content.strip():
            context = client.chat.completions.create(
            model="meta/llama-3.1-405b-instruct",
            messages=[{"role": "user", "content": f"Please explain the context of the paragraph: {content}"}],
            temperature=0.2,
            top_p=0.7,
            max_tokens=1024,
            stream=True
            )

            explanation = ""
            for response in context:
                if response.choices[0].delta.content is not None:
                    explanation += response.choices[0].delta.content 
            st.write (f"Explanation: {explanation}")
        else:
             st.write (f"Please input a content")

if __name__ == "__main__":
    main()