Spaces:
Runtime error
Runtime error
Threatthriver
commited on
Commit
•
51571c7
1
Parent(s):
99ccf3a
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
from huggingface_hub import InferenceClient
|
2 |
import gradio as gr
|
3 |
from datetime import datetime
|
|
|
4 |
|
5 |
API_URL = "https://api-inference.huggingface.co/models/"
|
6 |
|
@@ -16,8 +17,16 @@ def format_prompt(message, history):
|
|
16 |
prompt += f"[INST] {message} [/INST]"
|
17 |
return prompt
|
18 |
|
|
|
|
|
|
|
|
|
|
|
19 |
def generate(prompt, history):
|
20 |
"""Generate a response using the text generation model."""
|
|
|
|
|
|
|
21 |
# Check if the prompt is asking who created the bot
|
22 |
if "who created you" in prompt.lower():
|
23 |
return "I was created by Aniket Kumar and many more."
|
@@ -45,17 +54,6 @@ def generate(prompt, history):
|
|
45 |
yield output
|
46 |
return output
|
47 |
|
48 |
-
def greet_user():
|
49 |
-
"""Greet the user based on the time of day."""
|
50 |
-
current_hour = datetime.now().hour
|
51 |
-
|
52 |
-
if current_hour < 12:
|
53 |
-
return "Good morning! How can I assist you today?"
|
54 |
-
elif 12 <= current_hour < 18:
|
55 |
-
return "Good afternoon! How can I assist you today?"
|
56 |
-
else:
|
57 |
-
return "Good evening! How can I assist you today?"
|
58 |
-
|
59 |
def create_interface():
|
60 |
"""Create the Gradio interface."""
|
61 |
customCSS = """
|
@@ -68,7 +66,6 @@ def create_interface():
|
|
68 |
with gr.Blocks(css=customCSS) as demo:
|
69 |
gr.ChatInterface(
|
70 |
generate,
|
71 |
-
initial_message=greet_user(), # Add the greeting feature here
|
72 |
)
|
73 |
|
74 |
demo.queue().launch(debug=True)
|
|
|
1 |
from huggingface_hub import InferenceClient
|
2 |
import gradio as gr
|
3 |
from datetime import datetime
|
4 |
+
from textblob import TextBlob # for typo correction
|
5 |
|
6 |
API_URL = "https://api-inference.huggingface.co/models/"
|
7 |
|
|
|
17 |
prompt += f"[INST] {message} [/INST]"
|
18 |
return prompt
|
19 |
|
20 |
+
def correct_typos(text):
|
21 |
+
"""Correct typos in the text using TextBlob."""
|
22 |
+
corrected_text = str(TextBlob(text).correct())
|
23 |
+
return corrected_text
|
24 |
+
|
25 |
def generate(prompt, history):
|
26 |
"""Generate a response using the text generation model."""
|
27 |
+
# Correct typos in the prompt
|
28 |
+
prompt = correct_typos(prompt)
|
29 |
+
|
30 |
# Check if the prompt is asking who created the bot
|
31 |
if "who created you" in prompt.lower():
|
32 |
return "I was created by Aniket Kumar and many more."
|
|
|
54 |
yield output
|
55 |
return output
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
def create_interface():
|
58 |
"""Create the Gradio interface."""
|
59 |
customCSS = """
|
|
|
66 |
with gr.Blocks(css=customCSS) as demo:
|
67 |
gr.ChatInterface(
|
68 |
generate,
|
|
|
69 |
)
|
70 |
|
71 |
demo.queue().launch(debug=True)
|