loayshabet commited on
Commit
e437fbf
·
verified ·
1 Parent(s): 249a4b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -20,7 +20,8 @@ OPENROUTER_API_URL = "https://openrouter.ai/api/v1/chat/completions"
20
  SUMMARIZER_MODELS = {
21
  "Default (facebook/bart-large-cnn)": "local_bart",
22
  "Free Model (distilbart-cnn-6-6)": "local_distilbart",
23
- "OpenRouter (Claude-3)": "anthropic/claude-3-haiku"
 
24
  }
25
 
26
  CACHE_SIZE = 500
@@ -100,19 +101,21 @@ def summarize_text(text, model_name):
100
 
101
  is_arabic = detect_language(text)
102
 
103
- if is_arabic or model_name == "OpenRouter (Claude-3)":
104
- logger.info("Using OpenRouter for summarization")
105
  headers = {
106
  "Authorization": f"Bearer {OPENROUTER_API_KEY}",
107
- "HTTP-Referer": "https://localhost:7860", # Replace with your actual domain
108
  "X-Title": "News Summarizer App",
109
  "Content-Type": "application/json"
110
  }
111
 
112
  prompt = f"Please provide a concise summary of the following news article in the same language as the original text. Keep the summary brief and focused on key points:\n\n{text}"
113
 
 
 
114
  data = {
115
- "model": "anthropic/claude-3-haiku",
116
  "messages": [{"role": "user", "content": prompt}],
117
  "max_tokens": 150
118
  }
@@ -224,7 +227,6 @@ def get_summary(tech_sources, business_sources, science_sources, world_sources,
224
  logger.error(f"Error in get_summary: {str(e)}")
225
  return f"An error occurred while processing your request: {str(e)}"
226
 
227
- # Gradio Interface
228
  # Gradio Interface
229
  demo = gr.Blocks()
230
 
@@ -278,7 +280,7 @@ with demo:
278
  )
279
 
280
  summarize_button = gr.Button("Get News Summary")
281
- summary_output = gr.HTML(label="News Summary") # Changed from gr.Textbox to gr.HTML
282
 
283
  summarize_button.click(
284
  get_summary,
 
20
  SUMMARIZER_MODELS = {
21
  "Default (facebook/bart-large-cnn)": "local_bart",
22
  "Free Model (distilbart-cnn-6-6)": "local_distilbart",
23
+ "OpenRouter (Claude-3)": "anthropic/claude-3-haiku",
24
+ "OpenRouter (GPT-4)": "openai/gpt-4"
25
  }
26
 
27
  CACHE_SIZE = 500
 
101
 
102
  is_arabic = detect_language(text)
103
 
104
+ if is_arabic or model_name in ["OpenRouter (Claude-3)", "OpenRouter (GPT-4)"]:
105
+ logger.info(f"Using OpenRouter with model {model_name} for summarization")
106
  headers = {
107
  "Authorization": f"Bearer {OPENROUTER_API_KEY}",
108
+ "HTTP-Referer": "https://localhost:7860",
109
  "X-Title": "News Summarizer App",
110
  "Content-Type": "application/json"
111
  }
112
 
113
  prompt = f"Please provide a concise summary of the following news article in the same language as the original text. Keep the summary brief and focused on key points:\n\n{text}"
114
 
115
+ model_id = SUMMARIZER_MODELS[model_name]
116
+
117
  data = {
118
+ "model": model_id,
119
  "messages": [{"role": "user", "content": prompt}],
120
  "max_tokens": 150
121
  }
 
227
  logger.error(f"Error in get_summary: {str(e)}")
228
  return f"An error occurred while processing your request: {str(e)}"
229
 
 
230
  # Gradio Interface
231
  demo = gr.Blocks()
232
 
 
280
  )
281
 
282
  summarize_button = gr.Button("Get News Summary")
283
+ summary_output = gr.HTML(label="News Summary")
284
 
285
  summarize_button.click(
286
  get_summary,