Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,8 @@
|
|
| 1 |
import os
|
| 2 |
import requests
|
| 3 |
-
from bs4 import BeautifulSoup
|
| 4 |
|
| 5 |
api_token = os.environ.get("TOKEN")
|
| 6 |
-
API_URL = "https://api-inference.huggingface.co/models/meta-llama/
|
| 7 |
headers = {"Authorization": f"Bearer {api_token}"}
|
| 8 |
|
| 9 |
def query(payload):
|
|
@@ -32,34 +31,27 @@ user
|
|
| 32 |
assistant
|
| 33 |
'''
|
| 34 |
})
|
| 35 |
-
|
| 36 |
print("API Response:", output) # Print the full API response
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
return "unknown"
|
| 47 |
|
| 48 |
-
#
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
print("\nAnalyzing sentiment...")
|
| 60 |
-
sentiment = analyze_sentiment(pl7_text)
|
| 61 |
-
print(f"\nSentiment category: {sentiment}")
|
| 62 |
-
else:
|
| 63 |
-
print("No post found with class 'pl-7'")
|
| 64 |
-
else:
|
| 65 |
-
print(f"Error {response.status_code} when retrieving {url}")
|
|
|
|
| 1 |
import os
|
| 2 |
import requests
|
|
|
|
| 3 |
|
| 4 |
api_token = os.environ.get("TOKEN")
|
| 5 |
+
API_URL = "https://api-inference.huggingface.co/models/meta-llama/Llama-2-7b-chat-hf"
|
| 6 |
headers = {"Authorization": f"Bearer {api_token}"}
|
| 7 |
|
| 8 |
def query(payload):
|
|
|
|
| 31 |
assistant
|
| 32 |
'''
|
| 33 |
})
|
| 34 |
+
|
| 35 |
print("API Response:", output) # Print the full API response
|
| 36 |
|
| 37 |
+
if isinstance(output, list) and len(output) > 0:
|
| 38 |
+
generated_text = output[0].get('generated_text', '')
|
| 39 |
+
print("Generated Text:", generated_text) # Print the generated text
|
| 40 |
|
| 41 |
+
# Extract the first non-empty line as the category
|
| 42 |
+
lines = [line.strip().lower() for line in generated_text.split('\n') if line.strip()]
|
| 43 |
+
if lines:
|
| 44 |
+
return lines[0]
|
| 45 |
return "unknown"
|
| 46 |
|
| 47 |
+
# Entrée personnalisée pour le test
|
| 48 |
+
custom_post_content = """
|
| 49 |
+
This is a sample post about fine-tuning models for specific tasks.
|
| 50 |
+
It discusses various techniques and best practices for adjusting models.
|
| 51 |
+
"""
|
| 52 |
+
|
| 53 |
+
print("Post content:")
|
| 54 |
+
print(custom_post_content)
|
| 55 |
+
print("\nAnalyzing sentiment...")
|
| 56 |
+
sentiment = analyze_sentiment(custom_post_content)
|
| 57 |
+
print(f"\nSentiment category: {sentiment}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|