Spaces:
Sleeping
Sleeping
import streamlit as st | |
import requests | |
import os | |
# Get Together API key from environment variable | |
TOGETHER_API_KEY = os.getenv('TOGETHER_API_KEY') | |
# Streamlit UI | |
st.title("Movie Review Sentiment Analysis") | |
# User input for movie review | |
zero_shot_prompt = st.text_area("Enter zero-shot prompt:", "") | |
one_shot_prompt = st.text_area("Enter one-shot prompt:", "") | |
few_shot_prompt = st.text_area("Enter few-shot prompts:", "") | |
# Together API endpoint | |
endpoint = 'https://api.together.xyz/inference' | |
# Determine the prompt based on user input | |
if st.button("Analyze Zero-shot"): | |
prompt = zero_shot_prompt | |
elif st.button("Analyze One-shot"): | |
prompt = one_shot_prompt | |
elif st.button("Analyze Few-shot"): | |
prompt = few_shot_prompt | |
else: | |
prompt = "" | |
# Make a request to Together API if a prompt is provided | |
if prompt: | |
response = requests.post(endpoint, json={ | |
"model": 'togethercomputer/RedPajama-INCITE-7B-Base', | |
"prompt": prompt, | |
"top_p": 1, | |
"top_k": 40, | |
"temperature": 0.8, | |
"max_tokens": 1, | |
"repetition_penalty": 1, | |
}, headers={ | |
"Authorization": f"Bearer {TOGETHER_API_KEY}" | |
}) | |
# Display the output | |
st.text("Sentiment Analysis Result:") | |
st.text(response.json()['output']['choices'][0]['text']) |