File size: 1,437 Bytes
9ced53d
06db259
4bf022d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122887b
 
4bf022d
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import os

from huggingface_hub import InferenceClient

# Get token from Space secrets
API_TOKEN = os.getenv("HF_TOKEN")

# Initialize the Inference Client
client = InferenceClient(token=API_TOKEN)

# Title of the app
st.title("Sentence Improver App")

# Text input from the user
user_input = st.text_input("Enter a sentence to improve:", "I goed to the park and play.")

# Button to trigger the correction
if st.button("Improve Sentence"):
    if user_input:
        # Create a prompt for the LLM to improve the sentence
        prompt = f"Correct and improve this sentence: '{user_input}'"
        
        # Call the LLM via Hugging Face Inference API
        try:
            response = client.text_generation(
                prompt,
                model="mistralai/Mixtral-8x7B-Instruct-v0.1",  # You can change this to another model
                #model="deepseek-ai/deepseek-coder-6.7b-instruct",
                max_new_tokens=100,
                temperature=0.7,
            )
            # Extract the improved sentence (remove the prompt part if included)
            improved_sentence = response.strip()
            st.write("Improved Sentence:", improved_sentence)
        except Exception as e:
            st.error(f"Error calling the LLM: {str(e)}")
    else:
        st.warning("Please enter a sentence first!")
else:
    st.write("Enter a sentence and click the button to see it improved!")