Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import random
|
| 2 |
import pandas as pd
|
| 3 |
import seaborn as sns
|
|
@@ -6,16 +30,14 @@ import nltk
|
|
| 6 |
import gradio as gr
|
| 7 |
from nltk.sentiment import SentimentIntensityAnalyzer
|
| 8 |
from textblob import TextBlob
|
| 9 |
-
import warnings
|
| 10 |
from transformers import (
|
| 11 |
AutoTokenizer,
|
| 12 |
AutoModelForCausalLM,
|
| 13 |
AutoModelForSequenceClassification,
|
| 14 |
)
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
|
| 18 |
-
nltk.download('vader_lexicon', quiet=True)
|
| 19 |
|
| 20 |
# --- Emotion Analyzer ---
|
| 21 |
class EmotionalAnalyzer:
|
|
@@ -84,9 +106,10 @@ class EmotionalAnalyzer:
|
|
| 84 |
plt.close()
|
| 85 |
return path
|
| 86 |
except Exception:
|
| 87 |
-
return None
|
| 88 |
|
| 89 |
# --- Text Completion LLM ---
|
|
|
|
| 90 |
tokenizer = AutoTokenizer.from_pretrained("diabolic6045/ELN-Llama-1B-base")
|
| 91 |
model = AutoModelForCausalLM.from_pretrained("diabolic6045/ELN-Llama-1B-base")
|
| 92 |
|
|
@@ -171,4 +194,5 @@ with gr.Blocks(title="ELN LLaMA 1B Enhanced Demo") as app:
|
|
| 171 |
comp_button = gr.Button("Complete Text")
|
| 172 |
comp_button.click(generate_completion, inputs=[comp_text, comp_temp, comp_len], outputs=comp_output)
|
| 173 |
|
|
|
|
| 174 |
app.launch(share=True)
|
|
|
|
| 1 |
+
import warnings
|
| 2 |
+
# Suppress FutureWarnings
|
| 3 |
+
warnings.filterwarnings("ignore", category=FutureWarning)
|
| 4 |
+
|
| 5 |
+
# --- Monkey Patch for Gradio's Schema Parsing ---
|
| 6 |
+
# This patch prevents errors when a boolean appears in a schema where an iterable is expected.
|
| 7 |
+
try:
|
| 8 |
+
import gradio_client.utils as client_utils
|
| 9 |
+
original_get_type = client_utils.get_type
|
| 10 |
+
|
| 11 |
+
def patched_get_type(schema):
|
| 12 |
+
# If schema is a bool, simply return a generic type string.
|
| 13 |
+
if isinstance(schema, bool):
|
| 14 |
+
return "Any"
|
| 15 |
+
if not isinstance(schema, dict):
|
| 16 |
+
return "Any"
|
| 17 |
+
# Otherwise, call the original function.
|
| 18 |
+
return original_get_type(schema)
|
| 19 |
+
|
| 20 |
+
client_utils.get_type = patched_get_type
|
| 21 |
+
except Exception as e:
|
| 22 |
+
# If the patch fails for some reason, log the error and continue.
|
| 23 |
+
print("Warning: Failed to patch gradio_client.utils.get_type:", e)
|
| 24 |
+
|
| 25 |
import random
|
| 26 |
import pandas as pd
|
| 27 |
import seaborn as sns
|
|
|
|
| 30 |
import gradio as gr
|
| 31 |
from nltk.sentiment import SentimentIntensityAnalyzer
|
| 32 |
from textblob import TextBlob
|
|
|
|
| 33 |
from transformers import (
|
| 34 |
AutoTokenizer,
|
| 35 |
AutoModelForCausalLM,
|
| 36 |
AutoModelForSequenceClassification,
|
| 37 |
)
|
| 38 |
|
| 39 |
+
# Download necessary NLTK data
|
| 40 |
+
nltk.download("vader_lexicon", quiet=True)
|
|
|
|
| 41 |
|
| 42 |
# --- Emotion Analyzer ---
|
| 43 |
class EmotionalAnalyzer:
|
|
|
|
| 106 |
plt.close()
|
| 107 |
return path
|
| 108 |
except Exception:
|
| 109 |
+
return None
|
| 110 |
|
| 111 |
# --- Text Completion LLM ---
|
| 112 |
+
# Load the fine-tuned LLaMA model and tokenizer
|
| 113 |
tokenizer = AutoTokenizer.from_pretrained("diabolic6045/ELN-Llama-1B-base")
|
| 114 |
model = AutoModelForCausalLM.from_pretrained("diabolic6045/ELN-Llama-1B-base")
|
| 115 |
|
|
|
|
| 194 |
comp_button = gr.Button("Complete Text")
|
| 195 |
comp_button.click(generate_completion, inputs=[comp_text, comp_temp, comp_len], outputs=comp_output)
|
| 196 |
|
| 197 |
+
# Launch the Gradio app (remove share=True if not needed)
|
| 198 |
app.launch(share=True)
|