Spaces:
Running
Running
Create Check 2.py
Browse files- pages/Check 2.py +49 -0
pages/Check 2.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
import os
|
4 |
+
|
5 |
+
# Define the endpoint and API key
|
6 |
+
api_url = "https://api-inference.huggingface.co/models/meta-llama/Meta-Llama-3-8B-Instruct"
|
7 |
+
api_key = os.getenv('HFSecret')
|
8 |
+
|
9 |
+
headers = {
|
10 |
+
"Authorization": f"Bearer {api_key}"
|
11 |
+
}
|
12 |
+
|
13 |
+
# API call function
|
14 |
+
def call_huggingface_api(prompt):
|
15 |
+
data = {"inputs": prompt, "parameters": {"max_length": 500, "temperature": 0.5}}
|
16 |
+
response = requests.post(api_url, headers=headers, json=data)
|
17 |
+
|
18 |
+
if response.status_code != 200:
|
19 |
+
st.error(f"Error: {response.status_code} - {response.text}")
|
20 |
+
return None
|
21 |
+
|
22 |
+
return response.json()
|
23 |
+
|
24 |
+
# Streamlit layout
|
25 |
+
st.title("Sentiment Analysis, Summarization, and Keyword Extraction")
|
26 |
+
|
27 |
+
text_input = st.text_area("Enter text for analysis")
|
28 |
+
|
29 |
+
if st.button("Analyze"):
|
30 |
+
if text_input:
|
31 |
+
# Sentiment Analysis
|
32 |
+
sentiment_prompt = f"Perform sentiment analysis on the following text: {text_input}"
|
33 |
+
sentiment_result = call_huggingface_api(sentiment_prompt)
|
34 |
+
if sentiment_result:
|
35 |
+
st.write("Sentiment Analysis Result:", sentiment_result[0]['generated_text'])
|
36 |
+
|
37 |
+
# Summarization
|
38 |
+
summarization_prompt = f"Summarize the following text: {text_input}"
|
39 |
+
summarization_result = call_huggingface_api(summarization_prompt)
|
40 |
+
if summarization_result:
|
41 |
+
st.write("Summarization Result:", summarization_result[0]['generated_text'])
|
42 |
+
|
43 |
+
# Keyword Extraction (Using LLM, not RAKE)
|
44 |
+
keyword_prompt = f"Extract important keywords from the following text: {text_input}"
|
45 |
+
keyword_result = call_huggingface_api(keyword_prompt)
|
46 |
+
if keyword_result:
|
47 |
+
st.write("Keyword Extraction Result:", keyword_result[0]['generated_text'])
|
48 |
+
else:
|
49 |
+
st.warning("Please enter some text for analysis.")
|