NassimeBejaia commited on
Commit
4bf022d
·
verified ·
1 Parent(s): 9ced53d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -2
app.py CHANGED
@@ -1,4 +1,40 @@
1
  import streamlit as st
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
 
3
+
4
+ from huggingface_hub import InferenceClient
5
+
6
+ # Get token from Space secrets
7
+ API_TOKEN = os.getenv("HF_TOKEN")
8
+
9
+ # Initialize the Inference Client
10
+ client = InferenceClient(token=API_TOKEN)
11
+
12
+ # Title of the app
13
+ st.title("Sentence Improver App")
14
+
15
+ # Text input from the user
16
+ user_input = st.text_input("Enter a sentence to improve:", "I goed to the park and play.")
17
+
18
+ # Button to trigger the correction
19
+ if st.button("Improve Sentence"):
20
+ if user_input:
21
+ # Create a prompt for the LLM to improve the sentence
22
+ prompt = f"Correct and improve this sentence: '{user_input}'"
23
+
24
+ # Call the LLM via Hugging Face Inference API
25
+ try:
26
+ response = client.text_generation(
27
+ prompt,
28
+ model="mistralai/Mixtral-8x7B-Instruct-v0.1", # You can change this to another model
29
+ max_new_tokens=100,
30
+ temperature=0.7,
31
+ )
32
+ # Extract the improved sentence (remove the prompt part if included)
33
+ improved_sentence = response.strip()
34
+ st.write("Improved Sentence:", improved_sentence)
35
+ except Exception as e:
36
+ st.error(f"Error calling the LLM: {str(e)}")
37
+ else:
38
+ st.warning("Please enter a sentence first!")
39
+ else:
40
+ st.write("Enter a sentence and click the button to see it improved!")