Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,10 @@
|
|
| 1 |
# -*- coding: utf-8 -*-
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
-
import
|
| 5 |
-
import os
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
|
| 10 |
def get_completion(code_snippet):
|
| 11 |
# Code examples to illustrate the output
|
|
@@ -44,14 +43,9 @@ def get_completion(code_snippet):
|
|
| 44 |
"""
|
| 45 |
|
| 46 |
try:
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
max_tokens=300 # Reduced max tokens to limit usage
|
| 51 |
-
)
|
| 52 |
-
return response['choices'][0]['message']['content']
|
| 53 |
-
except openai.error.RateLimitError:
|
| 54 |
-
return "Quota exceeded. Please try again later."
|
| 55 |
except Exception as e:
|
| 56 |
return f"An error occurred: {str(e)}"
|
| 57 |
|
|
|
|
| 1 |
# -*- coding: utf-8 -*-
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
+
from transformers import pipeline
|
|
|
|
| 5 |
|
| 6 |
+
# Load the text generation model (GPT-2)
|
| 7 |
+
text_generator = pipeline('text-generation', model='gpt2')
|
| 8 |
|
| 9 |
def get_completion(code_snippet):
|
| 10 |
# Code examples to illustrate the output
|
|
|
|
| 43 |
"""
|
| 44 |
|
| 45 |
try:
|
| 46 |
+
# Generate text using the Hugging Face model
|
| 47 |
+
response = text_generator(prompt, max_length=300, num_return_sequences=1)
|
| 48 |
+
return response[0]['generated_text']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
except Exception as e:
|
| 50 |
return f"An error occurred: {str(e)}"
|
| 51 |
|