Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,7 +12,7 @@ if not API_KEY:
|
|
| 12 |
raise ValueError("Hugging Face API key not found. Please set the 'APIHUGGING' secret.")
|
| 13 |
|
| 14 |
# Initialize Hugging Face Inference Client
|
| 15 |
-
client = InferenceClient(
|
| 16 |
|
| 17 |
# Function to extract text from various file types
|
| 18 |
def extract_file_content(file_path):
|
|
@@ -43,20 +43,13 @@ def get_bot_response(file, prompt):
|
|
| 43 |
# Extract content from the uploaded file
|
| 44 |
file_content = extract_file_content(file)
|
| 45 |
|
| 46 |
-
# Prepare
|
| 47 |
-
|
| 48 |
-
{"role": "user", "content": f"{prompt}\n\nFile Content:\n{file_content}"}
|
| 49 |
-
]
|
| 50 |
|
| 51 |
-
# Call Hugging Face API
|
| 52 |
-
|
| 53 |
-
model="Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 54 |
-
messages=messages,
|
| 55 |
-
max_tokens=500
|
| 56 |
-
)
|
| 57 |
|
| 58 |
-
|
| 59 |
-
return bot_response.choices[0].message.content
|
| 60 |
except Exception as e:
|
| 61 |
return f"Error: {str(e)}"
|
| 62 |
|
|
|
|
| 12 |
raise ValueError("Hugging Face API key not found. Please set the 'APIHUGGING' secret.")
|
| 13 |
|
| 14 |
# Initialize Hugging Face Inference Client
|
| 15 |
+
client = InferenceClient(api_token=API_KEY, model="Qwen/Qwen2.5-Coder-32B-Instruct")
|
| 16 |
|
| 17 |
# Function to extract text from various file types
|
| 18 |
def extract_file_content(file_path):
|
|
|
|
| 43 |
# Extract content from the uploaded file
|
| 44 |
file_content = extract_file_content(file)
|
| 45 |
|
| 46 |
+
# Prepare input for the model
|
| 47 |
+
input_text = f"{prompt}\n\nFile Content:\n{file_content}"
|
|
|
|
|
|
|
| 48 |
|
| 49 |
+
# Call Hugging Face API for text completion
|
| 50 |
+
response = client.text_generation(input=input_text, max_new_tokens=50000)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
+
return response
|
|
|
|
| 53 |
except Exception as e:
|
| 54 |
return f"Error: {str(e)}"
|
| 55 |
|