Reverted to initial CODE
Browse files
app.py
CHANGED
|
@@ -1,10 +1,9 @@
|
|
| 1 |
import os
|
| 2 |
import gc
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
import keras_nlp
|
| 5 |
from huggingface_hub import login
|
| 6 |
-
import markdown
|
| 7 |
-
from bs4 import BeautifulSoup
|
| 8 |
|
| 9 |
# Get the API key from environment variable
|
| 10 |
api_key = os.getenv("HUGGINGFACE_API_KEY")
|
|
@@ -18,11 +17,6 @@ login(api_key)
|
|
| 18 |
model_path = "MNLobago/EcoWise_model"
|
| 19 |
gemma_lm = keras_nlp.models.GemmaCausalLM.from_preset(f"hf://{model_path}")
|
| 20 |
|
| 21 |
-
# Function to convert Markdown to HTML (preserving the formatting)
|
| 22 |
-
def markdown_to_html(markdown_text):
|
| 23 |
-
html = markdown.markdown(markdown_text) # Convert Markdown to HTML
|
| 24 |
-
return html # Return the HTML with formatting preserved
|
| 25 |
-
|
| 26 |
class GemmaChat:
|
| 27 |
def __init__(self, model, max_length=150, system=""):
|
| 28 |
self.model = model
|
|
@@ -42,10 +36,7 @@ class GemmaChat:
|
|
| 42 |
response = self.model.generate(prompt, max_length=self.max_length)
|
| 43 |
model_response = response.replace(prompt, "").strip()
|
| 44 |
|
| 45 |
-
#
|
| 46 |
-
model_response = markdown_to_html(model_response)
|
| 47 |
-
|
| 48 |
-
# Sanitize the response if necessary (optional)
|
| 49 |
model_response = model_response.rstrip('?')
|
| 50 |
|
| 51 |
# Ensure the response ends with a period if it doesn't end with a punctuation mark
|
|
@@ -70,7 +61,7 @@ def chat_with_model(input_text):
|
|
| 70 |
demo = gr.Interface(
|
| 71 |
fn=chat_with_model,
|
| 72 |
inputs="text",
|
| 73 |
-
outputs="
|
| 74 |
description="π Welcome to EcoWise, your go-to climate-savvy chatbot! I'm here to help you."
|
| 75 |
)
|
| 76 |
|
|
|
|
| 1 |
import os
|
| 2 |
import gc
|
| 3 |
+
import psutil
|
| 4 |
import gradio as gr
|
| 5 |
import keras_nlp
|
| 6 |
from huggingface_hub import login
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Get the API key from environment variable
|
| 9 |
api_key = os.getenv("HUGGINGFACE_API_KEY")
|
|
|
|
| 17 |
model_path = "MNLobago/EcoWise_model"
|
| 18 |
gemma_lm = keras_nlp.models.GemmaCausalLM.from_preset(f"hf://{model_path}")
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
class GemmaChat:
|
| 21 |
def __init__(self, model, max_length=150, system=""):
|
| 22 |
self.model = model
|
|
|
|
| 36 |
response = self.model.generate(prompt, max_length=self.max_length)
|
| 37 |
model_response = response.replace(prompt, "").strip()
|
| 38 |
|
| 39 |
+
# Sanitize the response
|
|
|
|
|
|
|
|
|
|
| 40 |
model_response = model_response.rstrip('?')
|
| 41 |
|
| 42 |
# Ensure the response ends with a period if it doesn't end with a punctuation mark
|
|
|
|
| 61 |
demo = gr.Interface(
|
| 62 |
fn=chat_with_model,
|
| 63 |
inputs="text",
|
| 64 |
+
outputs="chatbot",
|
| 65 |
description="π Welcome to EcoWise, your go-to climate-savvy chatbot! I'm here to help you."
|
| 66 |
)
|
| 67 |
|