Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,28 +6,41 @@ import time
|
|
| 6 |
|
| 7 |
# Default model
|
| 8 |
MODEL = "ZeppelinCorp/Charm_15"
|
| 9 |
-
text_generator =
|
| 10 |
|
| 11 |
def load_model(model_name):
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
def generate_response(prompt, model_name):
|
| 15 |
global MODEL, text_generator
|
| 16 |
-
|
|
|
|
| 17 |
MODEL = model_name
|
| 18 |
text_generator = load_model(model_name)
|
|
|
|
|
|
|
| 19 |
|
| 20 |
loading_animation = gr.update(value=". . .", visible=True)
|
| 21 |
time.sleep(1) # Simulate loading delay
|
| 22 |
-
response = text_generator(prompt, max_length=200)[0]['generated_text']
|
| 23 |
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
def google_search(query):
|
| 27 |
loading_animation = gr.update(value="Searching…", visible=True)
|
| 28 |
time.sleep(1) # Simulate search delay
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
def upload_image(image):
|
| 33 |
return "Image uploaded successfully."
|
|
@@ -40,8 +53,12 @@ def analyze_reasoning(input_text):
|
|
| 40 |
|
| 41 |
def switch_model(new_model):
|
| 42 |
global MODEL, text_generator
|
| 43 |
-
|
| 44 |
text_generator = load_model(new_model)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
return f"Switched to {new_model}"
|
| 46 |
|
| 47 |
iface = gr.Interface(
|
|
|
|
| 6 |
|
| 7 |
# Default model
|
| 8 |
MODEL = "ZeppelinCorp/Charm_15"
|
| 9 |
+
text_generator = None
|
| 10 |
|
| 11 |
def load_model(model_name):
|
| 12 |
+
try:
|
| 13 |
+
return pipeline("text-generation", model=model_name)
|
| 14 |
+
except Exception as e:
|
| 15 |
+
return None
|
| 16 |
|
| 17 |
def generate_response(prompt, model_name):
|
| 18 |
global MODEL, text_generator
|
| 19 |
+
|
| 20 |
+
if model_name != MODEL or text_generator is None:
|
| 21 |
MODEL = model_name
|
| 22 |
text_generator = load_model(model_name)
|
| 23 |
+
if text_generator is None:
|
| 24 |
+
return "Error loading model. Please try another one."
|
| 25 |
|
| 26 |
loading_animation = gr.update(value=". . .", visible=True)
|
| 27 |
time.sleep(1) # Simulate loading delay
|
|
|
|
| 28 |
|
| 29 |
+
try:
|
| 30 |
+
response = text_generator(prompt, max_length=200)[0]['generated_text']
|
| 31 |
+
return gr.update(value=response, visible=True)
|
| 32 |
+
except Exception as e:
|
| 33 |
+
return f"Error generating response: {e}"
|
| 34 |
|
| 35 |
def google_search(query):
|
| 36 |
loading_animation = gr.update(value="Searching…", visible=True)
|
| 37 |
time.sleep(1) # Simulate search delay
|
| 38 |
+
|
| 39 |
+
try:
|
| 40 |
+
results = [url for url in search(query, num=5, stop=5, pause=2)]
|
| 41 |
+
return "\n".join(results)
|
| 42 |
+
except Exception as e:
|
| 43 |
+
return f"Error in search: {e}"
|
| 44 |
|
| 45 |
def upload_image(image):
|
| 46 |
return "Image uploaded successfully."
|
|
|
|
| 53 |
|
| 54 |
def switch_model(new_model):
|
| 55 |
global MODEL, text_generator
|
| 56 |
+
|
| 57 |
text_generator = load_model(new_model)
|
| 58 |
+
if text_generator is None:
|
| 59 |
+
return f"Failed to switch to {new_model}. Try another model."
|
| 60 |
+
|
| 61 |
+
MODEL = new_model
|
| 62 |
return f"Switched to {new_model}"
|
| 63 |
|
| 64 |
iface = gr.Interface(
|